I'm using a TcpClient and calling Close when I want to drop the client's connection to my server. My understanding is that Close will call Shutdown on the socket if it hasn't already been called.
Can anyone explain what "terminated" means in the context below? From what I've observered, it means that the party that calls Shutdown will send a hard reset (RST) rather than going through the graceful shutdown sequence (FIN, ACK...).
From: https://msdn.microsoft.com/en-us/library/system.net.sockets.socket.shutdown(v=vs.110).aspx
Setting how to Receive specifies that subsequent calls to Receive are not allowed. This has no effect on lower protocol layers. If you are using a connection-oriented protocol, the connection is terminated if either of the following conditions exist after a call to Shutdown :
- Data is in the incoming network buffer waiting to be received.
- More data has arrived.
Based on this, if I wanted to do a graceful shutdown I must try to empty my local receiving buffer before calling Close.
Is that right or is there a way to guarantee a graceful shutdown occurs?