Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can a socket server receive an empty message? [closed]

Tags:

python

sockets

I have a socket client and a socket server.

The server is in python, and is synchronous.

Sometimes the clients send an empty string, and I'm then required to identify this situation, and return a response.

With the code below, the server just keeps on waiting, and the clients don't get anything in return, unless it sends something more "fat" (i.e. a longer message).

How can I capture the empty message? Is it at all possible?

This is 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... )
like image 579
Berry Tsakala Avatar asked Oct 27 '25 19:10

Berry Tsakala


1 Answers

  • In TCP, there is no such thing as an empty message, so zero means a peer disconnect.
  • In UDP, there is no such thing as a peer disconnect, so zero means an empty datagram.

As you describe a multi-threaded socket server, it would seem to be TCP, in which case your requirement doesn't make sense. You can't send an empty message over TCP. You would have to use a superimposed protocol for everything.

like image 150
user207421 Avatar answered Oct 29 '25 07:10

user207421