user2318083
user2318083

Reputation: 587

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

Upvotes: 0

Views: 2531

Answers (1)

laike9m
laike9m

Reputation: 19368

You're getting this wrong. Since you import *, just use AF_INET and SOCK_DGRAM

>>> from socket import *
>>> clientSocket = socket(AF_INET, SOCK_DGRAM)

Tested on my machine using Py3.4

Upvotes: 2

Related Questions