2

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))
Paul Manta
  • 30,618
  • 31
  • 128
  • 208
  • 1
    In server.py: you have to bind the socket to your public IP - or is that a typo? – djf Jun 11 '13 at 11:55
  • By default mysql new installations are only allowed to connect from localhost. Check if this is your problem and change the configuration to allow remote connections. – Ander2 Jun 11 '13 at 12:00
  • @djf Trying to do that gives "OSError: [WinError 10049] The requested address is not valid in its context". – Paul Manta Jun 11 '13 at 12:04
  • `[WinError 10049]` is a completely different error. It indicates that `MY_PUBLIC_IP` is not an IP on that machine. Make sure it's correct. Your problem is a possible duplicate of: http://stackoverflow.com/questions/4657347/socket-error-ip-address-not-valid-in-its-context-python – djf Jun 11 '13 at 12:22

2 Answers2

1

It's most likely your firewall or router if you have on. Try configuring your firewall to allow access on that port, and doing port forwarding if you're using a router.

NightW.
  • 73
  • 1
  • 1
  • 9
0

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

sock.bind(('0.0.0.0', 8888))
radu.ciorba
  • 1,024
  • 1
  • 8
  • 14