I have a function within an application where a client connected to a
server continuously sends data. The code on the server side is of the
following form:
Socket socket = receiveSocket;
NetworkStream networkStream = new NetworkStream (socket);
System.IO.StreamReader streamReader = new System.IO.StreamReader
(networkStream);
while (socket.Connected)
{
streamReader.ReadLine();
}
// Do something else when no longer connected
I would like the server to stop reading from the buffer if the client
closes the connection. Instead, the server continues to read blank
lines continuously. No exceptions are thrown. How can I stop this
behaviour and obtain the behaviour that I would like?