I have a few questions about finishing a tcp connection.
A client connects to my server using Tcp, after accepting the client with
listener.BeginAcceptTcpClient(ConnectionEstabilishedCallback, null);
, I start to read withnetworkStream.BeginRead(....)
.
What happens when the client disconnects while I wait for a message? (e.g. it loses power, internet, etc)
How do I know when it happens?If after a successful read, I do some stuff, and then call
networkStream.Close(); client.Close();
What will the client see? How do I terminate the connection "gracefully"?What happens if I'm waiting for a read (with BeginRead), and then (on a different thread) close the same stream?
EDIT TO ADD: I do have a ping-pong message going on between the client and server. Is that enough? If I don't receive ping, terminate my NetworkStream? surely there must be something better.