Resolved Receiving Data from NetworkStream

sectioneight

New member
Joined
Jul 31, 2009
Messages
2
Programming Experience
1-3
Hello,

I am curious if there is a way to receive data from a socket in the chunks as it was sent. For instance, in my client program if I send something like:

"VERSION=1.0"

then I send:

"NAME=MyName"

When I receive it from the server I get: "VERSION=1.0NAME=MyName". Instead of receiveing it seperately.

What is the proper way to handle, using a delimiter? But what if the data being sent is large than my blocksize, and it misses some data? This has been boggling my mind trying to figure out a good way to do this.

Thanks in advance!
 
Last edited:
If strings are single lines then using a StreamWriter/Reader you can WriteLine/ReadLine to get line by line, else there is BinaryWriter/Reader where you can Write(String) and ReadString which keeps track of the string length transmitted.
For different kind of data you can transmit the data length so receiver know how much to read, even across multiple receive buffers, or use serialization to read/write packets of data.
 
Perfect,

I found the Binary Reader/Writer worked best. For some reason I could not get the Stream Reader/Writer to work right.

Thanks a million!
 
Back
Top