Re: Problem with application trying to read data from a network stream when the socket is closed



Nicholas Paldino [.NET/C# MVP] wrote:

I recommend using the NetworkStream, and reading byte by byte yourself, parsing apart the new line on your own. If the socket disconnects, then no more bytes will be returned to you (if the socket is closed).

That would solve the problem in terms of program execution. I don't understand why Socket.Connected wouldn't return false in the example code, though. In the program I'm writing, it will leave a thread running unnecessarily and because of the way the data is expected to be received, I can't use a timeout to close it.
.