[英]AttributeError from client sockets in python
I'm getting an attribute error from running the client side of the program, I'm pretty sure I did it everything correctly but apparently not. 我从运行程序的客户端时遇到属性错误,我敢肯定我所做的一切都正确,但显然没有。
Here's the code: 这是代码:
from socket import *
serverName = 'hostname'
serverPort = 12000
clientSocket = socket(socket.AF_INET, socket.SOCK_DGRAM)
message = raw_input('Input lowercase sentence:')
clientSocket.sendto(message,(serverName, serverPort))
modifiedMessage, serverAddress = clientSocket.recvfrom(2048)
print modifiedMessage
clientSocket.close()
This is the error I get: 这是我得到的错误:
Traceback (most recent call last):
File "UDPClient.py", line 4, in <module>
clientSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
AttributeError: type object '_socketobject' has no attribute 'socket'
EDIT: 编辑:
Traceback (most recent call last):
File "UDPClient.py", line 6, in <module>
clientSocket.sendto(message,(serverName,serverPort))
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
You're getting this wrong. 你错了。 Since you import *
, just use AF_INET
and SOCK_DGRAM
由于import *
,因此只需使用AF_INET
和SOCK_DGRAM
>>> from socket import *
>>> clientSocket = socket(AF_INET, SOCK_DGRAM)
Tested on my machine using Py3.4 使用Py3.4在我的机器上测试
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.