[Python] how to receive a socket message with an empty data?

Discussão em 'Python' iniciado por Stack, Julho 25, 2025.

  1. Stack

    Stack Membro Participativo

    i have a socket client and a socket server.

    (the server is in python, and is synchroneous.)

    sometimes the clients send an empty string. i'm required to identify this situation, and return a response.

    with this code, the server just keeps on waiting, and the client's don't get anything in return, unless it sends something mroe "fat" ;)

    how can i capture the empty message? is it at all possible?

    that's my server code:

    import SocketServer

    def multi_threaded_socket_server():

    class MyRequestHandler(SocketServer.BaseRequestHandler):
    def handle(self):
    while True:
    print 'waiting for client calls...'
    received = self.request.recv( PACKET_SIZE )
    (handle request... )

    Continue reading...

Compartilhe esta Página