0 votes
in Programming by (580 points)

I've been trying to implement a server-client connection, here is my code-


import socket

server = socket.socket()
server.bind(('', 2112))
print('Server created with port 2112')


import socket

##Public_IP is the Public IP address of my router
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((Public_IP, 2112))

Both Server.py and Client.py are running on my computer(server). It works just fine when I replace Public_IP with '', but when I use Public_IP, it gives the following error-

TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

Is it because I'm running both Server.py and Client.py on the same computer? Please let me know what I'm doing wrong.

Setting up port forwarding -

Public IP

Port forwarding

Private IP address of server

I followed this tutorial for setting up port forwarding.

I also tried replacing the empty string in Server.py with my private IP address-

server.bind(('', 2112))

Please log in or register to answer this question.