Reading data from tcpclient

  • Thread starter Thread starter Joe Wright
  • Start date Start date
J

Joe Wright

Hello,

I've been having trouble receiving data from a tcpclient. My problem is that
unlike all of the samples found on the internet i'm sending files instead of
just strings. I've noticed that I need to handle my buffer being filled
multiple times if the data is longer than the buffer size and also that if
the data is sent too fast to the server then it seems that my buffer can
contain the last part of my first batch of data and the beginning of
another. Does anyone have a sub you use to parse the bytes? Also, what is a
good way to end a message that I can check for. Any help would be
appreciated.
 
Joe Wright said:
I've been having trouble receiving data from a tcpclient. My problem is that
unlike all of the samples found on the internet i'm sending files instead of
just strings. I've noticed that I need to handle my buffer being filled
multiple times if the data is longer than the buffer size and also that if
the data is sent too fast to the server then it seems that my buffer can
contain the last part of my first batch of data and the beginning of
another. Does anyone have a sub you use to parse the bytes? Also, what is a
good way to end a message that I can check for. Any help would be
appreciated.

"End of message" depends entirely on the server protocol. The server
should either specify the length before sending the data, or it should
disconnect after sending the data.

As for the rest - could you post the code you're using? You should just
be able to read the stream as a normal stream...
 
I guess instead of sending data from the client all at once i should send
one command, wait for a confirmation response, and send the next. Is that
the basis for most protocols?
 
Joe Wright said:
I guess instead of sending data from the client all at once i should send
one command, wait for a confirmation response, and send the next. Is that
the basis for most protocols?

You can send all the data from the client in one go, but you'll need to
prefix it with the length, or close the connection afterwards, or have
some other "end of data" signalling mechanism. (Personally I'm a fan of
length prefixing.)
 
Back
Top