kryonet
kryonet copied to clipboard
UDP Connection Problem
Hi, I'm trying build a simple online game with libgdx and new to networking.
Using these videos to learn how to create a simple client/server connection. I have all the code in the videos properly but when i try to initialize as:
MPServer server = new MPServer(80,6672);
MPClient client = new MPClient(80,6672,5000);
server.start();
client.connect("127.0.0.1");
client.disconnect();
server.stop();
I have the input and the error (as you can see it disconnects immediately after being connected);
00:00 INFO: [kryonet] Server opened. Client started 00:00 INFO: Connecting: /127.0.0.1:80/6672 00:00 INFO: [kryonet] Connection 1 connected: /127.0.0.1 00:00 INFO: [kryonet] Connection 1 disconnected. java.net.SocketException: Connection is closed. at com.esotericsoftware.kryonet.UdpConnection.send(UdpConnection.java:99) at com.esotericsoftware.kryonet.Client.connect(Client.java:179) at com.esotericsoftware.kryonet.Client.connect(Client.java:110)
1 - When this error happened, I was using this line of code to connect in my client class
client.connect(TIMEOUT, serverIP, TCP_PORT, UDP_PORT);
2 - But after changing it to this, there is no error, no problem :
client.connect(TIMEOUT,serverIP,TCP_PORT);
Like I said, I'm a newbie to networking and I did not understand the problem here. I think I solved it only not using UDP Port but still not understand what is wrong when i used UDP.
Also, my port variables are : TCP : 80 and UDP : 6672. Tried with different UDP Port numbers but still the same error.
Thanks for any helps and given clues.
Happy and Confused Update :
I think I got the problem. Previously, I had written server.bind(TCP_PORT)
. I changed it to server.bind(TCP_PORT, UDP_PORT)
and got no error with the output of :
00:00 INFO: [kryonet] Server opened. 00:00 INFO: Connecting: /127.0.0.1:80/80 00:00 INFO: [kryonet] Connection 1 connected: /127.0.0.1 00:00 INFO: [kryonet] Connection 1 connected: /127.0.0.1 00:00 INFO: [kryonet] Connection 1 disconnected. 00:00 INFO: [kryonet] Closing server connections... 00:00 INFO: [kryonet] Connection 1 disconnected. 00:00 INFO: [kryonet] Server closed.
If this issue is resolved, don't forget to close it :)