Port forwarding with access point and multiplayer in godot

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Cyber-Kun

Ok so I know this question doesn’t have a lot to do with the GODOT engine but I figured someone on here might have dealt with a similar situation in the past and could lend me their guidence.
essentially I want to use port forwarding for my multiplayer fps in godot. but I’m having trouble getting it set up. I probably don’t understand enough about how it works but anyway. I have 2 routers. one is the main router wich is connected to the internet and the other is an access point to wich my pc is connected. both connections are wired. I’m having trouble setting up the port forwarding so that someone accross the internet can connect to my device. now I was told that when attempting this the person connecting to my device wich will be the host would need my external IP address along with the external port number and then I assumed that since there are two routers I would have to forward from the main router to the second and from the second to my device(host). now I got it set up that way and I’m using port 9999 in all fields and the ip PF rule in the first router is set to the accesspoint’s ip and the ip for PF rule on the access point is set to my computer. I then used Open Port Check Tool - Test Port Forwarding on Your Router to check if the port of “my_external_ip”:9999 is open but no matter what I do it says the port is closed no matter what I do. I tried setting up a quick listening script in python to check for incoming connections but I couldn’t get that to work. sorry for the long winded explination but I really need some guidence I’ve never used port forwarding so I don’t know what is what here pleas help

Ok so I found a problem. the external ip i get from curl ifconfig.me or whatismyip.com. is not unique to my device… when I check on other computers on my network I get the same external IP address for all of them. would I have to setup DynDNS? to get a domainName?
I don’t know. I’m very confused by this. I thought the ip from whatismyip.com would be unique to the machine that I am currently typing on but that doesn’t seem to be the case.
how do I now go about making a multiplayer game with port forwarding if I can’t access the server remotely with port forwarding?

Cyber-Kun | 2023-04-27 14:55

:bust_in_silhouette: Reply From: godot_dev_

If I understand correctly, you have the following setup:

  • Internet ------ (IP1) external router ------ (IP2) internal router ----- (IP3) PC hosting python
    It could be due to the following

  • The external IP address (IP1 above) is wrong (check this site to confirm what your external IP address is)

  • It could be a firewall issue on the device hosting the Python scripts. Make sure to create a rule in you firewall to allow incoming connections on port 9999

  • It could be an anti-virus issue. Some anti-viruses have their own firewall (I think McAfee does this). So also create a rule for port 9999 if this is the case

  • You may have incorrectly configured you external router when opening the port.

  • Double check to make sure the port 9999 is being forwarded to your internal router

  • Double check and confirm your internal router’s IP address IP2 above) is properly tied to open port 9999 rule

  • You may have incorrectly configured you internal router when opening the port.

  • Double check to make sure the port 9999 is being forwarded to your PC hosting the python script

  • Double check and confirm your PC’s IP address (IP3 above) is properly tied to open port 9999 rule

  • Make sure your python script is implemented correctly by having a local device (connected to the internal router) ping (or otherwise try and communicate with) the Python script. If communication doesn’t work on a LAN, you have a Python script issue.

  • Note that sometimes the IP address of devices change on a LAN (due to new devices connecting and what not). This might be the source of the issue. You can configure your routers to assign static IP address based on MAC addresses to the devices involved in your setup. This will limit the possibility for error

  • If you double checked all the above, the only last thing I can think of is making sure the Python script is running and can be pinged when you perform the open port checker

I’ve set my machine to a static ip out of the dhcp range and I did use the right ip wich I got from whatismyip.com and also using curl ifconfig.me in the cmd.
here is the python script I don’t really know how it works or it might be set up wrong:

import socket

HOST = 'my-external-ip'  # set the host IP address to listen on
PORT = 9999  # set the port number to listen on

# create a socket object
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.bind((HOST, PORT))  # bind the socket to the host and port
    s.listen()  # listen for incoming connections

print(f'Listening on {HOST}:{PORT}...')

conn, addr = s.accept()  # accept the connection

with conn:
    print(f'Connected by {addr}')
    while True:
        data = conn.recv(1024)  # receive data from the client
        if not data:
            break
        conn.sendall(data)

this script works when I leave the HOST empty. but when I put in my external Ip it won’t work and won’t listen to anything. it throws this error:
Traceback (most recent call last):
File “C:\Users\fuck you billGates\Desktop\PORT.py”, line 8, in
s.bind((HOST, PORT)) # bind the socket to the host and port
^^^^^^^^^^^^^^^^^^^^
OSError: [WinError 10049] The requested address is not valid in its context

Cyber-Kun | 2023-04-27 09:07

I also made rules in windows defender firewall>advanced>inbound rules to allow all connections on both tcp and udp ports 9999

Cyber-Kun | 2023-04-27 09:13

I believe the problem might be in the python script but I’m not sure. I will double check all the port forwarding rules on both routers. also the first router IP1 has a virtual server setting and port forwarding. from my understanding their both the same but should I maybe set a rule in virtual server as well since I only set the port forwarding rule?

Cyber-Kun | 2023-04-27 09:18

I was also considering using another port from 9999 as when i use a port checking service it says that the default ports like 80 are open but not port 9999

Cyber-Kun | 2023-04-27 09:28

I found a setting on the access point called WAN Port Ping and it’s disabled. should it be enabled?

Cyber-Kun | 2023-04-27 09:44

ok I seem to be having trouble setting up the access point(IP2) to have a static IP address on the main router. it’s unfortunately a HUAWEI B315. when I navigate to Ethernet settings I can choose the connection mode but even though I set it to static there on the main router it just shows the dynamic IP .151 instead of what I try to set it to

Cyber-Kun | 2023-04-27 10:34

According to a Python echo server guide, the address to use when binding is 127.0.0.1 (aka, localhost), not the external IP. I think this is because your telling the server that you will be hosting on this machine, not connecting to another server. Try changing the IP to 127.0.0.1 in your python script

godot_dev_ | 2023-04-27 13:42

Also, I recommend the first step you should focus on is getting your python script to work on a LAN without any router configuration (have it send a message back to a clientmachine on the same LAN as the python server). All the router config is futile is your python script is buggy.

godot_dev_ | 2023-04-27 13:59