Re: Segmented Data Over Sockets

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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


.



Relevant Pages

  • fax receiving problems
    ... I'm having a problem with a fax server at one of my client ... I recently installed the SBS 2003 fax server feature with a brand new ... Receiving is a little more tricky. ... see Help and Support Center at ...
    (microsoft.public.windows.server.sbs)
  • Error during delivery process
    ... A client of ours kept on receiving the same message over and over again. ... below from our own mail server: ... The following errors occurred during message delivery processing: ...
    (microsoft.public.exchange2000.admin)
  • Re: Doubt in Socket Program
    ... > Here i pasted Both Server and client code.. ... > I am sending Three message using multiple sends in same server code. ... > char *b; ... behavior by asking recv to write to where ever it happens to points to. ...
    (comp.lang.c)
  • Kerberos Error Message
    ... your client date indicates as 9/9/2004. ... on both server and clients are synchronized...? ... >I'm receiveing a kerberos error every few hours (The ... >Does anybody know why I'm receiving this error or where I ...
    (microsoft.public.win2000.security)
  • Re: System.WebException | The operation has timed out
    ... it is webserver that has timed out. ... But the error I am receiving is at ... When web server times out, the error received by the client is "The ...
    (microsoft.public.dotnet.framework.aspnet)