I have 2 computers on the same LAN. The first PC has an ip address 192.168.178.30, the other PC has an ip address 192.168.178.26.
Ping, traceroute, telnet, ssh, everything works between the two PCs. Both PCs run the same OS – CentOS 7 and both PCs have the same python version 2.7.5 (checked with the python -V command).
I copied simple python code from a computer networking book.
from socket import * serverName = '192.168.178.30' serverPort = 12000 clientSocket = socket(AF_INET, SOCK_STREAM) clientSocket.connect((serverName,serverPort)) sentence = raw_input('Input lowercase sentence: ') clientSocket.send(sentence) modifiedSentence = clientSocket.recv(1024) print 'From Server:', modifiedSentence clientSocket.close()
from socket import * serverPort = 12000 serverSocket = socket(AF_INET,SOCK_STREAM) serverSocket.bind(('192.168.178.30',serverPort)) serverSocket.listen(5) print 'The server is ready to receive' while 1: connectionSocket, addr = serverSocket.accept() sentence = connectionSocket.recv(1024) capitalizedSentence = sentence.upper() connectionSocket.send(capitalizedSentence) connectionSocket.close()
The code works when it is ran on the same PC (where the server is listening on localhost).
When I run the client code on one PC and the server code on the other PC I get this error on the client side.
Traceback (most recent call last): File "client.py", line 5, in <module> clientSocket.connect((serverName,serverPort)) File "/usr/lib64/python2.7/socket.py", line 224, in meth return getattr(self._sock,name)(*args) socket.error: [Errno 113] No route to host
Can someone help?
Check the firewall (on the server).
I stopped the firewall like Messa suggested and now it works.
service firewalld stop
I still don’t understand what the problem was. I even tried using different distributions. Do all distributions have strict firewalls or something. For example Ubuntu to Ubuntu, Ubuntu to CentOS, CentOS to Ubuntu I still had the same problem (error).
~]#supervisord Error: No config file found at default paths (/usr/etc/supervisord.conf, /usr/supervisord.conf, supervisord.conf, etc/supervisord.conf, /etc/supervisord.conf); use the -c option to specify a config file at a different path For help, use /usr/bin/supervisord -h
You should use
ln -s /etc/supervisor/supervisord.conf /usr/etc/supervisord.conf
None of this stuff worked for me. I just connected both the devices to the same WiFi network and my program worked!
You can also get this same error ([Errno 113] No route to host) if you are trying to connect 2 devices on the same network. the error can be fixed by double checking to make sure both devices are connected to the mqtt_client or whatever you are using. as soon as I connected the device I was trying to talk to everything worked as to be expected.I would also check to make sure the right IP_Address is being passed
We had this problem. I am putting our findings here in case anyone else stumbles across this question like I did.
Neither host has a default gateway.
We are connecting from Host B to Host A. (That is not a typo.) The
connect call succeeds, but when we try to
send data, we get errno 113 aka. EHOSTUNREACH aka. "No route to host".
The fix, of course, was to change the subnet on Host A to match Host B.
We were surprised to see this error on a connection within the same subnet / same LAN. And we were surprised that
connect succeeded followed by
send failing. And we were surprised to see this error on Host B even though the network configuration on Host B itself was fine.
Somehow, the incorrect subnet on Host A caused this error on Host B…
…and just like that, today I learned about ICMP "destination unreachable" messages.
service firewalld stop
This helped me. I turned them off on both devices to be safe.