Groups | Blog | Home
all groups > dotnet windows forms > june 2004 >

dotnet windows forms : Reading data from tcpclient


Joe Wright
6/8/2004 7:39:14 PM
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.

Jon Skeet [C# MVP]
6/9/2004 8:27:49 AM
[quoted text, click to view]

"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...

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
Joe Wright
6/9/2004 3:18:14 PM
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?


[quoted text, click to view]

Joe Wright
6/9/2004 4:54:39 PM
Thanks for the info, i'll definitely give length prefixing a try.


[quoted text, click to view]

Jon Skeet [C# MVP]
6/9/2004 9:37:27 PM
[quoted text, click to view]

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.)

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
AddThis Social Bookmark Button