Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting to myself through my public IP through TCP

I'm trying to connect to my own machine using my public IP. If I use 127.0.0.1 the connection is successful, but using the public IP results in the following error: "ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it".

According to MSDN, the error might appear because no server application is running; however, I did run the 'server.py' script first, before running 'client.py. What should I do to fix this?

server.py

from socket import *
sock = socket(AF_INET, SOCK_STREAM)
sock.bind(('127.0.0.1', 8888))
sock.listen(10)
conn, _ = sock.accept()

client.py

from socket import *
sock = socket(AF_INET, SOCK_STREAM)
sock.connect((MY_PUBLIC_IP, 8888))
like image 519
Paul Manta Avatar asked Nov 19 '25 21:11

Paul Manta


1 Answers

The server is listening on the loopback address only. Try this instead:

sock.bind(('0.0.0.0', 8888))
like image 176
radu.ciorba Avatar answered Nov 21 '25 11:11

radu.ciorba



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!