Note that exact reason why your code is frozen is not because you set too high request.recv() buffer size. Here is explained What means buffer size in socket.recv(buffer_size)
This code will work until it'll receive an empty TCP message (if you'd print this empty message, it'd show b''
):
while True:
data = self.request.recv(1024)
if not data: break
And note, that there is no way to send empty TCP message. socket.send(b'')
simply won't work.
Why? Because empty message is sent only when you type socket.close()
, so your script will loop as long as you won't close your connection.
As Hans L pointed out here are some good methods to end message.