title: Socket still listening after application crash
body: <p>I'm having a problem with one of my C++ applications on Windows 2008x64 (same app runs just fine on Windows 2003x64). </p>
  
  <p>After a crash or even sometimes after a regular shutdown/restart cycle it has a problem using a socket on port 82 it needs to receive commands. </p>
  
  <p>Looking at netstat I see the socket is still in listening state more than 10 minutes after the application stopped (the process is definitely not running anymore).</p>
  
  <pre><code>  TCP    0.0.0.0:82             LISTENING
  </code></pre>
  
  <p>I tried setting the socket option to REUSEADDR but as far as I know that only affects re-connecting to a port that's in TIME_WAIT state. Either way this change didn't seem to make any difference.</p>
  
  <pre><code>int doReuse = 1;
  setsockopt(listenFd, SOL_SOCKET, SO_REUSEADDR,
             (const char *)&amp;doReuse, sizeof(doReuse)); 
  </code></pre>
  
  <p>Any ideas what I can do to solve or at least avoid this problem?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Did netstat -an but this is all I am getting:</p>
  
  <pre><code>  TCP    0.0.0.0:82             0.0.0.0:0              LISTENING
  </code></pre>
  
  <p>For netstat -anb I get:</p>
  
  <pre><code>  TCP    0.0.0.0:82             0.0.0.0:0              LISTENING
   [System]
  </code></pre>
  
  <p>I'm aware of shutting down gracefully, but even if the app crashes for some reason I still need to be able to restart it.  The application in question uses an in-house library that internally uses Windows Sockets API.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Apparently there is no solution for this problem, so for development I will go with a proxy / tool to work around it. Thanks for all the suggestions, much appreciated.</p>