title: How to terminate a java program that listens for client's requests to create a socket?
body: <p>How do I make this program exit when I run it in terminal using the Java JDK in Ubuntu?</p>
  
  <p>I want to type in "end" when this program is running, but I can't get it to work.
  It listens for clients and calls a thread thingy to create a socket for the new client.
  I can't figure out how to make this program end. I tried everything.</p>
  
  <p>I started learning java yesterday.
  Please help me....</p>
  
  <pre><code>import java.net.*;          //jave lib
  import java.io.*;           //io lib
  
  public class MultiServerConnections {       //initiate class
  public static void main(String[] args) throws IOException {
  
      int portNum = 5342;                 //set server port number
      boolean listen = true;
  
      System.out.println("Listening for Connections");    //print message
  
      ServerSocket server_Socket = null;          //set server_Socket to null
      try {
  
  
  
          server_Socket = new ServerSocket(portNum);      //set server port
      } catch (IOException e) {
          System.err.println("Port " + portNum + " is unavailable"); //port is taken error
          System.exit(1);
      }
  
  BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in)); //set reader
  String input;
  
      //while (TCPglobals.checkRequests){
      while (listen == true){
      new MultiServer(server_Socket.accept()).start();
  
      input = stdIn.readLine();
      //if(TCPglobals.checkRequests == false) //|| (input = stdIn.readLine()) == "end")
      if(input == "end") {
          System.out.println("end connection?");
          System.exit(1);
      }
  
  }//while
  
      server_Socket.close(); //close server socket
  
  }
  </code></pre>
  
  <p>}</p>