1

I am building a simple UDP client, however, I am getting an error message "socket is not callable". I have checked the code and it can find the problem

I tried importing the module by using "from socket import *" but it didn't work.

import socket
serverName = 'hostname'
serverPort = 1200
clientSocket = socket(socket.AF_INET, socket.SOCK_DGRAM)
message = 'Testing the system'
clientSocket.sendto(message, (serverName, serverPort))
modifiedMessage, serverAddress = clientSocket.recvfrom(2048)
print(modifiedMessage)
clientSocket.close()

3 Answers 3

1

you need to import socket from socket module like this

import socket
from socket import socket as sk
serverName = 'hostname'
serverPort = 1200
clientSocket = sk(socket.AF_INET, socket.SOCK_DGRAM)

etc

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

Comments

0

I think you have named your program as socket.py or stored your program in a folder that contains socket.py . Either rename your file or delete them

Comments

0

Your code should work, you just need to change

clientSocket = socket(socket.AF_INET, socket.SOCK_DGRAM)

To

clientSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

You are trying to feed inputs to a module (socket) instead of the function inside the module (socket.socket)

Comments

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.