Close listening ServerSocket
<p>In my Server application I'm trying to handle the Server which is using ServerSocket like,</p>

<ol>
<li>Start the server and wait for connection.</li>
<li>Stop the server which is connected with a client.</li>
<li>Stop the server which is waiting for a client.</li>
</ol>

<p>I can able to start the server and make it to wait for client inside a thread using</p>

<pre><code>socket = serverSocket.accept();
</code></pre>

<p>What I want to do is I want manually close the socket which is waiting for connection, I have tried using,</p>

<pre><code>if (thread != null) {
     thread.stop();
     thread = null;
  }
  if (socket != null) {
     try {
        socket.close();
        socket = null;
     }
     catch (IOException e) {
        e.printStackTrace();
     }
  }
</code></pre>

<p>After executing the above code even though the socket becomes null, when I try to connect from client to server, the connection gets established, so my question is how to interrupt the serversocket which listening for connection over here,</p>

<pre><code>socket = serverSocket.accept();
</code></pre>
