> From: Rob Dixon [mailto:rob.di...@gmx.com] > > On 24/10/2011 13:14, Gary wrote: > > > > Effectively what happens is that I get a decent chunk of data the > > first few times around the loop, all of RECV_BUF_SIZE (512) length, > > then a final 44 bytes, and the code thinks it's done. Then when the > > code executes again with another command, the recv loop gets the final > > few > > 512 byte chunks it should have got before. > > > > Is there a decent set of documentation for how to use IO:Socket > > anywhere? Can anyone see what I'm doing wrong? (Probably I shouldn't > > be using send/recv, but without any hints from the documentation...) > > It sounds to me like your sender isn't flushing its output at the end of each > chunk? Because you're getting a short final buffer it seems pretty certain that > taht is all that's been sent.
There are a couple of things you need to keep in mind about TCP/IP. It is a stream based protocol. It guarantees that all of the bytes you send will reach the other end in the same order or you will get an error. But it makes no guarantees about delivery time or how those bytes will be grouped together. If there is any structure to the data, it is up to your application to parse the data so that it fits your structure. You need to make sure you have received just enough data to fill that structure once. If you don't have enough you have to wait for more. If you have too many, you need to hold on to the extra to start the next element. If you want a read() to return exactly as many bytes as the matching write() sent, you need UDP. But then you give up the delivery guarantee. Bob McConnell -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/