Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In almost all cases you are supposed to call <code>Shutdown</code> on a <code>Socket</code> or <code>TcpClient</code> before disposing it. Disposing rudely kills the connection.</p> <p>Your code basically contains a race condition with the TCP stack.</p> <p>Setting <code>NoDelay</code> is also a fix for this but hurts performance. Calling <code>Flush</code> IMHO still results an an disorderly shutdown. Don't do it because they are just hacks which paint over the problem by hiding the symptoms. Call <code>Shutdown</code>.</p> <p>I want to stress that <code>Shutdown</code> being called on the <code>Socket</code> is the <strong>only</strong> valid solution that I know of. Even <code>Flush</code> just forces the data onto the network. It can still be lost due to a network hickup. It will not be retransmitted after <code>Close</code> has been called because <code>Close</code> is a rude kill on the socket.</p> <p>Unfortunately <a href="http://support.microsoft.com/kb/821625" rel="nofollow noreferrer">TcpClient has a bug</a> which forces you to go to the underlying Socket to shut it down:</p> <pre><code>tcpClient.Client.Shutdown(); tcpClient.Close(); </code></pre> <p>According to Reflector, if you have ever accessed <code>GetStream</code> this problem arises and Close does not close the underlying socket. In my estimation this bug was produced because the developer did not really know about the importance of <code>Shutdown</code>. Few people know and many apps are buggy because of it. <a href="https://stackoverflow.com/questions/425235/how-to-properly-and-completely-close-reset-a-tcpclient-connection">A related question.</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload