1

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: port forwarding on my router

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! :)

Petr Marek
  • 59
  • 1
  • 7
  • Question: after you defined that port forwarding rule, did you save and restart the router? – RealSkeptic Oct 27 '19 at 11:46
  • I clicked on save settings. I tried to reboot device, but it change all local IP addresses, so my port forwarding rules are no valid then...So I can't reboot device, only save settings. Any more suggestions? – Petr Marek Oct 27 '19 at 12:00
  • You need to give your PC a fixed address in the DHCP based on its MAC address or configure it with a static IP and exclude that IP from DHCP. Then you'll be able to reboot the router. BTW, this question is off-topic for StackOverflow, because it's a question about configuration, not about programming. – RealSkeptic Oct 27 '19 at 12:14
  • Ok, when i reboot device again, it gives me same IP (even if I don't give my PC fixed address), so the port forwarding rules are right...but it still don't works...Any suggestions? – Petr Marek Oct 27 '19 at 13:21

1 Answers1

0

Your issue is about networking and network routing. Try to connect to your server from the outside of your local network. Somewhere from internet. Buy a VPS or ask your friend. First of all you can check your port is opened using nmap. If it were opened you are able to connect to your server. Otherwise it might be your D-LINK problem. I see you have 22 port forwarding already. When I used D-LINK DIR-600 router I have similar issue - port was adjusted correctly but I was not able to connect via opened port. And I could fix this issue only by using DD-WRT - unofficial firmware.

bvn13
  • 154
  • 11