Unable to connect to Python socket server from another network

Viewed 27

I am trying to create an online function for a simple multiplayer game, and am having trouble establishing a connection over the internet. My server is using

 SERVER = "0.0.0.0"  
 PORT = 5555
 server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 server.bind((SERVER, PORT))

and my client is using

self.client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.server = MY_PUBLIC_IP_ADDRESS
self.port = 5555
self.addr = (self.server, self.port)
self.initial = self.connect()

def get_initial(self):
    return self.initial

def get_command(self):
    return self.client.recv(512).decode()

def connect(self):
    try:
        self.client.connect(self.addr)
        return pickle.loads(self.client.recv(512))
    except Exception as e:
        print(e, 'connect failed')
        sleep(0.5)

def send(self, data):
    try:
        self.client.send(str.encode(data))
    except socket.error as e:
        print(e, "socket error (send failed)")
    except Exception as e:
        print(e)

Though this initially failed, it started working after I enabled port forwarding on port 5555. It even had noticeable ping, while running purely on the local network did not. I thought this meant it could connect over the internet, but when a friend tried to connect to my running server with their client from another network, they simply received the error "[WinError 10060] A connection attempt failed because the connected party did not respond after a period of time, or established connection failed because connected host has failed to respond" ("connect failed" followed it, with the error apparently occurring in the connect function). This same error comes up locally when trying to connect to the server when it isn't running. I didn't see any recognition of their connection attempt on my end. I tried disabling my firewall, but they still couldn't connect.

Does port forwarding need to be enabled for both users, or is there something else I can do on my end?

0 Answers
Related