0

How to receive all data from a connection in socketserver so that it the connection does not hang on the client side

class ConnectionHandler(BaseRequestHandler):
    def handle(self):
        data = b''
        while 1:
            tmp =  self.request.recv(1024)
            if not tmp:
                break
            data += tmp 
        print (data.decode())

on the client side I am using

    char text[] = "Hello world\n";
    SSL_write(ssl, text, sizeof(text));

    char tmp[20];
    int received = SSL_read (ssl, tmp, 20);
    printf("Server replied: [%s]\n", tmp);

but this causes the connection not to close and the client hangs, I am sure this is the case since replacing the while loop with self.request.recv(1024) receives the client message and outputs it but what if i don't know the message size of the client

loaded_dypper
  • 262
  • 3
  • 12

1 Answers1

0

Using self.request.recv() without an actual value on how many bytes to read seems to obtain the whole buffer from the client

loaded_dypper
  • 262
  • 3
  • 12