title: Make server don't stop listening socket connections
body: <p>I am creating a socket server and client in Java.</p>
  <p>My objective is that the server is always listening for connections and keeps them all at the same time.</p>
  <p>The problem is that the server stops after listening to one socket connection.</p>
  <p>Server Code</p>
  <pre><code>/*
   * To change this license header, choose License Headers in Project Properties.
   * To change this template file, choose Tools | Templates
   * and open the template in the editor.
   */
  package pkg1;
  
  import java.io.*;
  
  import java.net.*;
  
  class Servidor {
  
      static final int PUERTO = 5007;
  
      public Servidor() {
  
          try {
  
              int numCli = 0;
              ServerSocket skServidor = new ServerSocket(PUERTO);
  
              System.out.println(&quot;Escucho el puerto &quot; + PUERTO);
  
              for (;;) {
                  Socket skCliente = skServidor.accept(); // Crea objeto
  
                  numCli++;
  
                  InputStream is = skCliente.getInputStream();
                  byte[] mensaje = new byte[25];
                  is.read(mensaje);
                  System.out.println(new String(mensaje));
  
                   
                      if (new String(mensaje).equals(&quot;KEY007
  </code></pre>
  <p>Client Socket</p>
  <pre><code>package pkg1;
  import java.io.*;
  
  
  import java.net.*;
  
  
  class Cliente {
  
  
    static final String HOST = &quot;localhost&quot;;
  
  
    static final int PUERTO=5007;
  
  
    public Cliente( ) {
  
  
      try{
  
  
        Socket skCliente = new Socket( HOST , PUERTO );
  
  
        
        
      
  
          OutputStream os = skCliente.getOutputStream();
          String key =&quot;KEY007&quot;;
          os.write(key.getBytes());
          
          InputStream is = skCliente.getInputStream();
  
          
          
                  byte[] mensaje = new byte[25];
  
      is.read(mensaje);
      
          System.out.println(new String(mensaje));
  
  
        skCliente.close();
  
  
      } catch( Exception e ) {
  
  
        System.out.println( e.getMessage() );
  
  
      }
  
  
    }
  
  
    public static void main( String[] arg ) {
  
  
      new Cliente();
  
  
    }
  
  
  }
  </code></pre>
  <p>Right now this code works and it connects between the two, but after the server gets one connection the server activity stops.</p>
  <p>How can I make the server listen to all the socket connections and keep them all at the same time?</p>
  <p>Many thanks for the help, I have been trying for days.</p>