Re: Segmented Data Over Sockets
- From: "DJX" <djx@xxxxxxxxxxxxxxxx>
- Date: Wed, 13 Dec 2006 22:06:18 -0500
Just as others explained, if you send() N bytes from the client, it does not
mean that a single corresponding recv() on the server will receive N bytes.
It could receive less, or it could receive more if multiple send()'s have
been issued.
The only thing that is "guaranteed" is that the bytes will come to the
server in the same order in which they were sent.
I would also suggest that you send the struct length as part of a "header"
and use that to read the struct data instead of assuming a struct length of
260. That way you could support multiple versions of the client software
should you need to change the size of the struct in the future.
"Saul775" <Saul775@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:E731E35D-27A2-486B-A201-28B570F5D19E@xxxxxxxxxxxxxxxx
Hello, All:
I've -- hopefully -- one last question to ask about sockets.
I'm sending a structure over a socket from one computer to another;
however,
the router is breaking the stream into segments. I'd like to recombine
the
data on the receiving end. What is the accepted practice, or method, in
recombining data, so the structure is complete?
I've an idea, but I'm not sure if it's the accepted method. I will
receive
the data. If it's not the size -- in bytes -- of the structure, I will
parse
each byte of the local structure on the receiving end, copying bytes.
Then I
will continue to recv() until the amount of bytes received is equal to the
size of the structure. Again, this is just an idea, but I'm not sure if
there's an easier method or, better yet, a function that will concatenate
the
two byte streams for me and place it into my structure.
Thank you, all.
Saul775
.
- Follow-Ups:
- Re: Segmented Data Over Sockets
- From: William Stacey [C# MVP]
- Re: Segmented Data Over Sockets
- Prev by Date: Re: Segmented Data Over Sockets
- Next by Date: Re: Segmented Data Over Sockets
- Previous by thread: Re: Segmented Data Over Sockets
- Next by thread: Re: Segmented Data Over Sockets
- Index(es):
Relevant Pages
|