Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 2.7 [Errno 113] No route to host

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.

client.py

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()

server.py

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?

like image 208
ThePraetor Avatar asked Aug 21 '16 11:08

ThePraetor


2 Answers

Check the firewall (on the server).

like image 54
Messa Avatar answered Nov 03 '22 03:11

Messa


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).

like image 32
ThePraetor Avatar answered Nov 03 '22 03:11

ThePraetor