I am having problems connecting my online application to others through another network. I can give them hostAddress to connect when we are on the same network, but when we do it over the Internet, the generated host address does not allow the connection, nor does it use the ip address obtained from internet sites such as whatismyip.com
My biggest problem is not debugging this code, because it works over the network, but the server does not see attempts when we try to switch to different networks. In addition, the test port I am using is 2222.
InetAddress addr = InetAddress.getLocalHost();
String hostname = addr.getHostName();
System.out.println("Hostname: " + hostname);
System.out.println("IP: " + addr.getHostAddress());
I show the host on the server when it starts
if (isClient) {
System.out.println("Client Starting..");
clientSocket = new Socket(host, port_number);
} else {
System.out.println("Server Starting..");
echoServer = new ServerSocket(port_number);
clientSocket = echoServer.accept();
System.out.println("Warning, Incoming Game..");
}
source
share