How should I handle incomplete packet buffers?

Posted by Benjamin Manns on Stack Overflow See other posts from Stack Overflow or by Benjamin Manns
Published on 2010-03-15T01:02:00Z Indexed on 2010/03/15 1:09 UTC
Read the original article Hit count: 286

Filed under:
|
|
|

I am writing a client for a server that typically sends data as strings in 500 or less bytes. However, the data will occasionally exceed that, and a single set of data could contain 200,000 bytes, for all the client knows (on initialization or significant events). However, I would like to not have to have each client running with a 50 MB socket buffer (if it's even possible).

Each set of data is delimited by a null \0 character. What kind of structure should I look at for storing partially sent data sets?

For example, the server may send ABCDEFGHIJKLMNOPQRSTUV\0WXYZ\0123!\0. I would want to process ABCDEFGHIJKLMNOPQRSTUV, WXYZ, and 123! independently. Also, the server could send ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890LOL123HAHATHISISREALLYLONG without the terminating character. I would want that data set stored somewhere for later appending and processing.

Also, I'm using asynchronous socket methods (BeginSend, EndSend, BeginReceive, EndReceive) if that matters.

© Stack Overflow or respective owner

Related posts about c#

Related posts about sockets