0

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

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

4 Comments

Since we're on this same code would you happen to know why I get the gaierror under the new 'EDIT'? I have a server name and same port as the server but it's giving me that socket.gaierror.
@user2318083 serverName = '127.0.0.1', you aren't expecting hostname to work are you.
I fixed it but I did serverName = '' and it works also. @laike9m
@user2318083 The doc says: the empty string represents INADDR_ANY.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.