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.
I got my real IP by running "curl https://ipinfo.io/ip"- The IP you got is your IP over internet. The laptop you are trying to connect is over ethernet / intranet. So the local IP should be used. If you have laptops behind a common router the IP's could be something like 192.168.0.2, 192.168.0.3 etc depending on the subnet config of router.