我正在设置一个简单的客户端套接字(我的服务器套接字运行良好)。但我被一个小虫子卡住了。这是我的代码,这是错误。在网上找不到这个错误。
from socket import *
import sys
host=socket.gethostname()
#host=127.0.0.1
serverPort= 12345
clientSocket =socket(AF_INET,SOCK_STREAM)
clientSocket.connect((127.0.0.1,serverPort))
msg= raw_input("Input text here:")
clientSocket.send(msg)
modmsg= clientSocket.recv(1024)
print "from server", modmsg
clientSocket.close()错误:
Traceback (most recent call last):
File "tcp_client.py", line 5, in <module>
clientSocket.connect((serverName,serverPort))
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.gaierror: [Errno -5] No address associated with hostname发布于 2016-08-26 05:12:51
您的代码在这里不正确(您发布了运行的真实代码吗?):
connect采用一个参数,它是一个元组from socket import *,你就不能做socket.socket固定:
import socket
import sys
host=socket.gethostname()
serverPort= 12345
clientSocket = socket.socket(AF_INET,SOCK_STREAM)
clientSocket.connect((host,serverPort))
msg= raw_input("Input text here:")
clientSocket.send(msg)
modmsg= clientSocket.recv(1024)
print "from server", modmsg
clientSocket.close()现在,当我运行这段代码(我没有客户机)而不是您的错误时,我得到了正确的超时。
https://stackoverflow.com/questions/39158573
复制相似问题