The*_*tor 3 python sockets python-2.7
我在同一个局域网上有2台计算机.第一台PC的IP地址为192.168.178.30,另一台PC的IP地址为192.168.178.26.Ping,traceroute,telnet,ssh,两台PC之间的一切都可以正常工作.两台PC运行相同的操作系统 - CentOS 7,两台PC都具有相同的python版本2.7.5(使用python -V命令检查).
我从计算机网络书中复制了简单的python代码.
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()
Run Code Online (Sandbox Code Playgroud)
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()
Run Code Online (Sandbox Code Playgroud)
代码在同一台PC上运行时(服务器在localhost上监听).当我在一台PC上运行客户端代码而在另一台PC上运行服务器代码时,我在客户端遇到此错误.
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
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?
我像 Messa 建议的那样停止了防火墙,现在它可以工作了。
service firewalld stop
Run Code Online (Sandbox Code Playgroud)
我仍然不明白问题是什么。我什至尝试使用不同的发行版。是否所有发行版都有严格的防火墙之类的。例如 Ubuntu 到 Ubuntu,Ubuntu 到 CentOS,CentOS 到 Ubuntu 我仍然有同样的问题(错误)。