title: Unable to open a socket server
body: <p>I am trying to make a simple client and server connection. However the server does not seem to bind to the port appropriately.</p>
  
  <p>The code I am using for the server is written below:</p>
  
  <pre><code>class Server extends Thread
  {
      public boolean running = true;
  
      public Server(Main main) throws IOException
      {
          super();
          ServerSocket server_sock = new ServerSocket(8123);
  
          while (running)
          {
              new Connector(server_sock.accept(), main);
          }
          server_sock.close();
      }
  }
  
  class Connector extends Thread
  {
      public Connector(Socket c)
      {
          super();
          system.out.println("Connecting"+c.getRemoteSocketAddress()+":"+c.getLocalPort());
          c.setKeepAlive(true);
          //wait for the connection to end
          system.out.println("Disconnecting"+c.getRemoteSocketAddress()+":"+c.getLocalPort());
      }
  }
  </code></pre>
  
  <p>The client is rather simple, I just want to connect to the server (The lines shown below is run via another program in its main):</p>
  
  <pre><code>s = new Socket("127.0.0.1", 8123); // Start
  s.close(); // Stop
  </code></pre>
  
  <p>What happens: the server runs and does not throw any exceptions. Hopeful I ran the client where it threw an exception <code>Exception in thread "main" java.net.ConnectException: Connection refused: connect</code>.</p>
  
  <p>So I made a simple python client &amp; server pair to check the Java server / clients:</p>
  
  <p><em>Server:</em></p>
  
  <pre><code>from socket import *
  
  s = socket(AF_INET, SOCK_STREAM)
  s.bind(('', 8123))
  s.listen(1)
  conn, addr = s.accept()
  print("CONNECTED: ", addr)
  conn.close()
  </code></pre>
  
  <p><em>Client:</em></p>
  
  <pre><code>from socket import *
  
  s = socket(AF_INET, SOCK_STREAM)
  s.connect(('localhost', 8123))
  s.close()
  </code></pre>
  
  <p>I tested python server with python client as a sanity test, which worked just fine. I tested the python server with the java client and they both cooperated just fine. However, python client and java series does not work. My python server provides the error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Users\SIGABRT\Desktop\tcp.py", line 4, in &lt;module&gt;
      s.connect(('localhost', 8123))
  ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
  </code></pre>
  
  <p>Which typically means that the server is not started properly. So what am I doing wrong with the Java server client?</p>