0
我想連接使用TCP。在客戶端,我有以下代碼Python socket.error:[Errno 113]沒有路由到主機,但ping工程
import socket
BUFFER_SIZE = 1024
server_addres = ('172.16.1.52',3201)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(server_addres)
data = s.recv(BUFFER_SIZE)
s.close()
print "received data:", data
我使用運行它:
sudo python myProgram.py
此錯誤出現
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 113] No route to host
但是,如果我運行:
sudo ping 172.16.1.52
ping工作正常。我需要運行ping爲sudo,因爲運行它沒有sudo給出ping: icmp open socket: Operation not permitted
檢查任何防火牆。同時使用[\ [die.net \]:'traceroute'](https://linux.die.net/man/8/traceroute)檢查路線。 – CristiFati