I want to make server (for multiplayer game), but I can't connect to my pc through my public IP address. My server is programmed in Java like this:
int port = 60000;
int client_num = 0;
ClientHandler clientHandler;
try (ServerSocket serverSocket = new ServerSocket(port)) {
System.out.println("Server is listening on port " + port);
while (true) {
Socket client = serverSocket.accept();
System.out.println("New client connected: "+client);
}
} catch (IOException ex) {
System.out.println("Server exception: " + ex.getMessage());
ex.printStackTrace();
}
Client is programmed in javascript like this(I am using websockets):
var websocket = new WebSocket(
'ws://127.0.0.1:60000');
websocket.onopen = function () {
$('h1').css('color', 'green');
websocket.send("Hello");
$('h1').css('color', 'purple');
};
You can see, that I use the same port (60 000) in both-server and client. In client where I write IP address (ws://127.0.0.1) I can write localhost(127.0.0.1) or my private ip (192.168.0.100) - AND IT WORKS! But when I write there my public ip (something like 91...***), it dont work and server dont write message "New client connected:" (like in case of local host do)... So I thought that problem is in port forwarding. But I tried to port forward, as you can see in image:
But it still don't work. I also tried to use DMZ in my router. Same results. I also tried to turn off firewall and web shield of my anitivirus. Again same result...Even if i try to check if my port 60 000 is open with some online test (https://www.yougetsignal.com/tools/open-ports/) it say that my port is closed...So why it don't work? I have found out, that even if I turn on Apache which listen on ports 80 and 443, tools for checking open ports also show me this ports (80 and 443) as closed (even when I turn DMZ on my router)...WHY? Note: I am sure, that i use right local IP for setting up port forwarding and DMZ, I use IP which give me ipconfig(and also as I already wrote - client-server communication works when I use this local address (192.168.0.100) of my pc where server runs...) Please help me! :)