title: ServerSocket accept behavior
body: <p>I have the following snippet of code :</p>
  
  <pre><code>if (servsock == null) {
      System.out.println("HELLO1!");
      servsock = new ServerSocket(63456, 10);
      System.out.println("HELLO2!");
  }
  try {
      System.out.println("HELLO3!");
      sock = servsock.accept();
  } catch (Exception ex) {
      if (servsock != null &amp;&amp; !servsock.isClosed()) {
          System.out.println("PICO1!");
          servsock.close();
      }
      if (servsock != null &amp;&amp; servsock.isClosed()) {
          System.out.println("PICO2!");
          manager.log("SERVER SOCKET closed and nulled.");
          servsock = null;
      }
      sock = servsock.accept();
  }
  System.out.println("HELLO4!");
  is = sock.getInputStream();
  System.out.println("HELLO5!");
  bis = new BufferedInputStream(is);
  System.out.println("HELLO6!");
  </code></pre>
  
  <p>This code is run in a runnable's <code>run()</code> method, and when the file has been transferred, it is supposed to stop every communication.</p>
  
  <p>The curious thing is, that it is not a loop. The code does accept, does makes a file transfer, but I don't understand why the HELLO1 is again on my screen. Thus, the second time I try to run again this code, gives me "Connection refused".</p>
  
  <p>The "10" was a hack from me, but the original code, never uses backlog also. </p>
  
  <p>Any suggestion please ?</p>
  
  <p>The code running executing the previous is that :</p>
  
  <pre><code>final IClientInterface clientInterface = client.getClient();
  final prgHolder = new ProgHolder();
  Pong ftppong = new Pong();
  ftppong.setFileNames(bout64.toByteArray());
  ftppong.setDstFolder(dstFolder);
  prgHolder.setName("pong");
  prgHolder.setTask(pong);
  Thread t = new Thread(new Runnable() {
      public void run() {
          try {
              IClientInterface.execute(prgHolder);
          } catch (Exception ex) {
              ex.printStackTrace();
          }
      }
  });
  t.start();
  </code></pre>
  
  <p>The exact problem now is, that when I reach the new ServerSocket(63456) command, the client gets a "Connection Refused", but the program in the distant PC, is wide open and wide listener! "netstat" confirms that!  </p>
  
  <p>So I rerun (second time) the program from an alternate window, passes all HELLO messages and completes the job!  </p>
  
  <p>Then the Thread stops in the distant PC, and unbinds the port 63456!</p>
  
  <p>Why does it fail as code, but accepts incoming requests?</p>