0

I'm trying to setup a basic socket program using TCP connections in Python, such as creating a socket, binding it to a specific address and port, as well as sending and receiving a HTTP packet.

I'm having trouble receiving the request message from the client.

I'm using the following:

message = serverSocket.receive

But when I go to the socket, port and file that's in my server directory through my browser I get the following error from IDLE:

AttributeError: 'socket' object has no attribute 'receive'

Is this the wrong approach to receive a request message from a client?

2
  • Without seeing your entire program we can't be much help at all, but ... the tiny fragment you did show is so utterly different from the actual way this would be done in Python that I have to wonder whether you are reading a tutorial for the wrong programming language. Could you please tell us where you heard that serverSocket.receive was the thing to do? Commented Mar 23, 2016 at 19:48
  • Please read stackoverflow.com/help/mcve Commented Mar 23, 2016 at 19:49

2 Answers 2

1

In order to receive data from a client/server via TCP in python using sockets:

someData = sock.recv(1024)

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

Comments

0

That is because no method is defined in the socket class for receive as your error states. You should use:

socket.recv(bufsize)

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.