Hey,
I recently started out with networking but I already ran into a brickwall, my knowledge of networking is very little so I hope the fix will be rather simple.
Basically, I’m using Kryonet and so far just used the sample code on the page, so Running a Server and Connecting a Client, altered it a little so I can increase a number on the server by pressing space on the client… which works BUT
only when I do it on the same computer with 127.0.0.1 OR I also tried it on two different laptops which are connected to the same Router and used the (I guess internal?) IP 10.0.0.1 … both worked
But when I tried to connect to the server with the IP I get from for example http://www.whatsmyip.org/ it doesn’t work, unable to connect.
Server
[spoiler]
public class KryoServer {
public KryoServer() throws IOException{
Server server = new Server();
server.start();
server.bind(54555, 54777);
Kryo kryo = server.getKryo();
kryo.register(SomeRequest.class);
kryo.register(SomeResponse.class);
server.addListener(new Listener() {
public void received (Connection connection, Object object) {
if (object instanceof SomeRequest) {
Main.test++;
/* SomeRequest request = (SomeRequest)object;
System.out.println(request.text);
SomeResponse response = new SomeResponse();
response.text = "Thanks!";
connection.sendTCP(response); */
}
}
});
}
}
[/spoiler]
Client
[spoiler]
public class KryoClient {
Client client;
String IP;
public KryoClient(String IP) throws IOException{
this.IP = IP;
client = new Client();
client.start();
client.connect(5000, IP, 54555, 54777);
Kryo kryo = client.getKryo();
kryo.register(SomeRequest.class);
kryo.register(SomeResponse.class);
client.addListener(new Listener() {
public void received (Connection connection, Object object) {
if (object instanceof SomeResponse) {
SomeResponse response = (SomeResponse)object;
System.out.println(response.text);
}
}
});
}
public void sendRequest(){
SomeRequest request = new SomeRequest();
client.sendTCP(request);
}
}
[/spoiler]
Thanks