network help needed

nobody_ spam at spam.spam
Wed Oct 25 11:59:22 PDT 2006


> That is only discussing how to determine how much data you should read.
>  If you expect the data at a constant rate, and you're consuming it, this 
> shouldn't be a problem.

I thought that by defining the size it won't buffer anymore.

>
> That is, if each packet is going to be one double, or 10 doubles, you know 
> the length.  Prefixing things with the length will change nothing. It's 
> like putting a large sign on your car that says "CAR" just in case you 
> should forget what it is.
>
> My concern was that data might sit in the operating system's socket 
> buffer, but this probably won't be a worry.  Normally, packets are much 
> bigger than 4 bytes, though... but it depends on network card and router 
> settings, iirc.

Yes this was my concern too :(

>
> You should be able to use one port for two-way communication.  I honestly 
> have never used the "socketstream" and don't know of its quality.
>
> However, what you would probably want to do is make the socket 
> non-blocking and use Socket.select() to check if it is ready for reading 
> or for writing.  This way, your server side can determine if it needs to 
> read a stop/start command or should send data.
>
> For stop/start commands, you may want to use a fixed size, length 
> prefixing, or delimiting.  As the page you linked to states, you do want 
> to know how much to read; it makes it faster and cleaner.
>
> As an example, HTTP/1.0 only supported Content-Length (so you had to know 
> the entity size before hand) and was one connection per entity. HTTP/1.1 
> was a huge improvement in performance, because it uses a single connection 
> for multiple entities, allows for pipelining (asking for multiple entities 
> before receiving any), and uses length prefixing for the entity-body if 
> negotiated.
>
> All that said, your program sounds like it will be dealing with so few 
> bytes as to not be an issue anyway.... even at 24kB/s.
>
> Hope that helps.
>
Thanks, I will try and implement it now. I'll be back when its finished (or 
broken :D)
Now I need to read into multithreading... another totally new thing for me.
(I don't even know how one thead gets his data from another)
Greets 





More information about the Digitalmars-d-learn mailing list