Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read an incoming tcp stream until a delimiter is found?

How do you read an incoming tcp stream until a specific delimiter is found in C#? The only possible solution I have come up with is reading the incoming stream one byte at a time.

like image 924
functor Avatar asked Mar 11 '10 20:03

functor


1 Answers

Reading the TCP socket and scanning for a delimiter are two different things.

You can read all available data on a non-blocking socket, into a byte array/string, then scan the byte array for your delimiter. Do whatever else you need to do, including perhaps saving data after the delimiter for the next read attempt.

Its best to use some sort of buffer to add incoming data into so the socket operations don't exactly dictate handling of the data.

like image 56
codenheim Avatar answered Oct 26 '22 13:10

codenheim