title: Restart a TCP Server
body: <p>I have a TCP server in my android application. The server starts running immediately. With one button click, i want to stop the server and with another one, restart the server again.</p>
  
  <p>My server is like this:</p>
  
  <pre><code>serverSocket = new ServerSocket(1292);
  while (true) {
   Socket client = serverSocket.accept();            
   ServersClient s = new ServersClient(client);
   Thread clientThread = new Thread(s);
   clientThread.run();
  }
  </code></pre>
  
  <p>I successfully handle closing with this code:</p>
  
  <pre><code>serverSocket.close();
  </code></pre>
  
  <p>After this code, no clients can connect.</p>
  
  <p>What should i do to restart it now?</p>