1

Is there any way that I can read an incoming message from a client using 'socket' in python? What I am looking for is a way to do without using SocketServer. It doesn't work in my case. For example, I have the following piece of code to 'accept' the incoming connection? but how can I get the incoming string from this?

import socket

def serve(self):
    listener=socket.socket()
    listener.bind(('',6000))
    listener.listen(5)

    while True:
        sockadd, c =listener.accept()

        # can I write the accepted request string??? 
        # Is there a way to do it? 

I have tried listener.recv(1024) it gives an exception.

help please, thanks in advance.

1 Answer 1

2

sockadd is a socket representing the connection with the client here, so use it to send and receive message with the client.

data = sockadd.recv(1024)

Check the socket documentation, there are several samples.

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

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.