connecting to my computer via python sockets while behind a router

Viewed 30

I am trying to follow this question to connect to my laptop from another laptop over the internet. Both laptops are behind different routers and are running Ubuntu. Here is my server side code:

import socket

class Server():
  def __init__(self,Adress=('',5000),MaxClient=1):
      self.s = socket.socket()
      self.s.bind(Adress)
      self.s.listen(MaxClient)
  def WaitForConnection(self):
      self.Client, self.Adr=(self.s.accept())
      print('Got a connection from: '+str(self.Client)+'.')


s = Server()
s.WaitForConnection()

and client side code:

import socket

class Client():
    myIP = "123.456.789.123" # I got my real IP by running "curl https://ipinfo.io/ip"
    def __init__(self,Adress=(myIP,5000)):
        self.s = socket.socket()
        self.s.connect(Adress)

c = Client()

I started up server.py on the 'server laptop' by running python3 server.py and then ran python3 client.py on the 'client laptop' which resulted in this error:

line 7, in __init__
    self.s.connect(Adress)
ConnectionRefusedError: [Errno 111] Connection refused

I'd like to know where I should go from here to resolve this error and create the connection.

0 Answers
Related