[solved] kryonet works on localhost, but not on different computers

I’m developing a small multiplayer game that uses kryonet. So far, it works great on the same machine (localhost), but when I tested it on another computer, the client did connect but failed to finish connecting, if that makes any sense. Poking around in the source code of kryonet shows that the client did not do anything about the TCP registration packet sent by the server, even though the client’s thread has been started.

Error:

java.net.SocketTimeoutException: Connected, but timed out during TCP registration.
Note: Client#update must be called in a separate thread during connect.
	at com.esotericsoftware.kryonet.Client.connect(Client.java:161)
	at com.esotericsoftware.kryonet.Client.connect(Client.java:110)
	at projectmp.client.ConnectingScreen$1.run(ConnectingScreen.java:28)

The connecting code:

public void connectTo(final String host, final int port){
		setMessage("Closing client (if still connected)");
		main.client.stop();
		setMessage("Attempting to connect to " + host + ":" + port);
		main.client.start();
		
		Thread connector = new Thread(){
			
			@Override
			public void run(){
				try {
					main.client.connect(5000, host, port, port);
					Main.logger.info("Successfully connected to " + host + ":" + port);
					setMessage("Connected to server; sending handshake");
					
					PacketHandshake handshake = new PacketHandshake();
					handshake.username = Main.username + "";
					handshake.version = Main.version + "";
					main.client.sendTCP(handshake);
				} catch (Exception e) {
					e.printStackTrace();
					setMessage("");
					Main.ERRORMSG.setMessage("Failed to connect:\n" + e.toString());
					main.setScreen(Main.ERRORMSG);
				}
			}
			
		};
		connector.setDaemon(true);
		connector.start();
	}

The (kryonet) client IS being started before I attempt a connection. connectTo gets called when you click the connect button (on the GL thread).

Any help is appreciated! Thanks!

I’m not sure this is related, but maybe you need to forward the ports on the network you are running the server?

If it’s over LAN, that shouldn’t be necessary IIRC, but for outside of LAN it will be a problem: https://www.google.com/#q=java+nat+punchthrough

I should’ve mentioned that the other computer I’m testing it on is also on my network. The ports were forwarded already.

I just remembered something. If I’m correct, for some modems (including mine), you cannot connect using public IP. Only computers outside the network are able to connect using public IP.

I’m using the computer’s internal IP address (192.168.1.X). I can connect using the internal IP address to my own computer (running the server) but not to other computers.

Removing

main.client.start()

before attempting to connect also returns this same error every time. I’ll keep looking into it.

I solved it by updating kryonet to its newest build (2.22.0-RC1) which wasn’t on the kryonet maven, but on the com.esotericsoftware repo. That was definitely a strange solution, but a solution nonetheless.

Thanks for all the help!