Tai,
On Mon, Apr 9, 2012 at 8:11 AM, Nguyen, Tai <tai.nguyen@lmco.com> wrote:
The sender send a message similar to the following format.
Header: contain size of the message
Body: contain the payload;
The receiver reads the Header into a tempbuffer. Then check the size, and read more into the tempbuffer with an offset of sizeof( Header ).
This works fine for TCP socket. When I switch to use UDP socket, weird behaviours happen.
Read the header into the tempbuffer. However, when I try to read the body, I also get the header again. So the temp buffer turns out to look like this.
Header
Header
Body.
I strongly suggest you read more on *networking*, as this is a very basic issue having nothing to do with boost.
What you are encountering is the difference between TCP and UDP. TCP is streaming, whereas UDP is packet-oriented. Thus, when you read from TCP, you will only get AT MOST as many bytes as you request (you may get fewer). When you read from UDP, you will get exactly a single complete packet, though it may be out of sequence offers no guarantee of receipt (it does, however, offer a guarantee that if you receive it, the data received is what was sent within that packet).
Finally you will likely get better response to networking questions on lists focused on TCP/IP networking or bsd sockets. comp.unix.networking comes to mind, and I'm sure there are others as well.
Good luck,
-cj