I would add an additional loop which executes accept(). If connection terminates, a server should accept() again.
In addition to this: TCP socket implement a byte stream, not a message interface. Meaning the network stack is free to send data in single chunks, multiple messages in a chunk or even messages distributed to different chunks. Good software will handle this. If you want to avoid this complexity, then use UDP sockets.
See also the client_socket.recv(1024).decode('utf-8'). When data come in as chunks, then udp bytes may be split which will randomly result in errors then. As your data appear to contain plain ascii (?), perhaps decoding to ascii is better.
In addition to this: TCP socket implement a byte stream, not a message interface. Meaning the network stack is free to send data in single chunks, multiple messages in a chunk or even messages distributed to different chunks. Good software will handle this. If you want to avoid this complexity, then use UDP sockets.
See also the client_socket.recv(1024).decode('utf-8'). When data come in as chunks, then udp bytes may be split which will randomly result in errors then. As your data appear to contain plain ascii (?), perhaps decoding to ascii is better.
Statistics: Posted by ghp — Fri Jan 19, 2024 6:32 pm