Dor George Dor George - 19 days ago 6x
Python Question

Python: Connect using sockets via external IP

Today, I have made my very first sockets program - I made a client and a server that message each other (kind of like a chat) using sockets. When using the internal IP as 'host', The connection is established, otherwise using the external IP, no connection is established.

Edit 1:

s = socket.socket()
host = ''
port = 9999
s.connect((host, port))

host = ''
port = 9999
s = socket.socket()
s.bind((host, port))
connection, address = s.accept()

How will this work properly with, for example, a laptop? Since your IP changes each time you switch Wifi, how would I be able to create a program that would permanently work with this specific laptop?

I understand that I have to port-forward the specific port to a specific internal machine such as but what if I'm using a laptop and I don't have access to the WIFI router. I wouldn't have access to every router a laptop uses.

I want the code to be permanently compatible.


Use or portal. You install program on laptop which check your IP frequencly and sends current IP to portal which assigns this IP to your address like "". Then people can access your laptop using "" instead of IP address.

You always assign socket to IP of local network card (NIC) like WiFi. You can't assing to external IP. You have to config your router so requests to external IP:port will be send to your local IP:port. Of course Internet Provider routers can block your ports and it will not work.