I'm trying to implement Kryonet in my game and i'm facing some trouble. Using the source from the code i develop my server like that :
try {
this.server = new Server();
ServerManager.registerClasses(this.server);
this.server.addListener(new Listener() {
public void received(Connection connection, Object object) {
if(object instanceof PositionMessage) {
System.out.println("[SERVER] Message from ID : " + connection.getID() + " - " + ((PositionMessage)object).message);
}
}
});
this.server.bind(port);
this.server.start();
System.out.println("Server started on port " + port);
ServerManager.isLaunched = true;
} catch (IOException e) {
e.printStackTrace();
ServerManager.isLaunched = false;
}
And that's how my client is coded :
this.client = new Client();
ServerManager.registerClasses(this.client);
client.start();
client.addListener(new Listener() {
public void connected (Connection connection) {
System.out.println("Send");
PositionMessage pm = new PositionMessage();
pm.message = "Hi, i'm connected";
client.sendTCP(pm);
}
public void received (Connection connection, Object object) {
}
});
new Thread("Connect") {
public void run () {
try {
System.out.println("Connecting on " + ipServer + " au port " + port);
client.connect(5000, ipServer, port);
System.out.println("I am connected");
isConnected = true;
} catch (IOException ex) {
ex.printStackTrace();
System.out.println("The server doesn't exist");
isConnected = false;
}
}
}.start();
It works perfectly, the client can connect and the message is send and receive by the server. But with that code, the problem is that the server is only local and can't be access from the outside (or it is and i'm just bad at it...) so to bypass that i'm not using only a port to create the server, but a InetSocketAdress passing my ip adress. So i replaced the bind in the server code by this :
this.server.bind(socketAdresse, socketAdresse);
With socketAdresse =
ServerManager.socketAdresse = new InetSocketAddress(ipServer, port);
The server is created (at least it seems created, i can't find a way to find if the server is launched, but i have no exception catched. Now for example, if i create a server with my local ip (the same way i was doing without the InetSocketAddress) and the port 2302, the client never connect to the server and i have literally no message. It just tell me that on the client side that the connection was succesfull but the server never receive any information, + when i do a check on the client if it connected, it says "false".
So my problem is that when i don't use a InetSocketAdress, the client can connect fine on my local ip, but i want to be able to host on the web so i use an inetsocketadress but the problem is that a client can't connect to my server and it doesn't give me an error.
Thanks for the help !