5

I created a TCP server program (see server.py) to access the terminal of another computer (see client.py). When I use the client and server locally (only on my computer) everything is fine, however when the client is sending a request from a different computer, I receive this message on the client side :

Traceback (most recent call last):
  File "client.py", line 11, in <module>
    client.connect((serverIP, serverPort))
  File "/usr/lib/python2.7/socket.py", line 228, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 111] Connection refused

Note : the server is the computer which is being accessed by the client.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • can you ping your server from your remote client? – Stanton Aug 26 '15 at 21:31
  • No, I am unable to ping my server. –  Aug 26 '15 at 21:38
  • 2
    You'll need to figure that out first. What ip? Is a local intranet ip (e.g 10.10 or 192.168....) you can do an ifconfig on your server to determine the correct IP to use in your client – Stanton Aug 26 '15 at 21:41
  • Can you check if the firewall is blocking any external connections on the server? – alvits Aug 26 '15 at 22:02
  • Possible duplicate of [Why am I getting the error "connection refused" in Python? (Sockets)](http://stackoverflow.com/questions/16130786/why-am-i-getting-the-error-connection-refused-in-python-sockets) – pacholik Mar 02 '17 at 10:21
  • Your code listing is not available anymore. Please copy it in the question – UserK Jan 25 '18 at 10:40

2 Answers2

5

'Connection refused' means there was nothing listening at the IP:port you tried to connect to.

It comes from the target system, which means that the connection request got there and the refusal came back, so it isn't a firewall issue.

user207421
  • 305,947
  • 44
  • 307
  • 483
2

Solved it. I had to use the IP given to in when running ifconfig (192.168.1.***). I was binding to localhost, and thus I could not connect to the server remotely.