title: KryoNet: Client disconnects immediately after connecting
body: <p>This seems to be a popular problem, but I'm still having trouble finding a solution even after spending a lot of time troubleshooting.  I'm hoping there's an updated solution.</p>
  
  <p>I'm setting up a simple Server and Client with the KryoNet Java networking library.  My problem is that my client disconnects immediately after connecting to the server.</p>
  
  <p>Here is my code:</p>
  
  <p><strong>Server</strong></p>
  
  <pre><code>public class TheServer extends Listener {
  
      static Server server;
      static final int PORT = 8215;
  
      public static void main(String[] args) throws IOException {
          server = new Server();
          server.start();
          server.bind(PORT);
          server.addListener(new TheServer());
          System.out.println("server started on " + PORT);
      }
  
      public void connected(Connection c) {
          System.out.println("connected: " + c.getID());
      }
  
      public void disconnected(Connection c) {
          System.out.println("disconnected: " + c.getID());
      }
  
  }
  </code></pre>
  
  <p><strong>Client</strong></p>
  
  <pre><code>public class TheClient extends Listener {
  
      static Client client;
      static final String IP = "localhost";
      static final int PORT = 8215;
  
      public static void main(String[] args) throws IOException {
          client = new Client();
          client.start();
          client.connect(5000, IP, PORT);
          client.addListener(new TheClient());
          //client.setKeepAliveTCP(2000);
      }
  
  }
  </code></pre>
  
  <p>After running <code>TheServer</code> and then <code>TheClient</code>, my console prints: </p>
  
  <pre><code>server started on 8215
  connected: 1
  disconnected: 1
  </code></pre>
  
  <p>Note that the time between the connection and disconnection is almost immediate, certainly less than the connection timeout time I set. Also note that I commented out the <code>setKeepAliveTCP()</code> method because while I do not think it is necessary, I inserted it to see if it would work.</p>