I'm having an issue where outputs from two different clients in a Python client-server TCP application are interleaving with each other. For example:
Client connected to 0.0.0.0:3000
hello world
[1.1.1.1:55845] hello world from client 2
how are[1.1.1.1:55845] hello world again
you doing
In this example, client 1 says "hello world" and client 2 says "hello world from client 2". When client 1 starts to type, client 2 sends a message "hello world again", which interleaves with the message that client 1 is about to type. Then, client 1 is forced to type the rest of the message on the next line.
Is there a way to make sure that when client 1 is typing a message, client 2's message either goes on a line above or generally does not interfere with the line the text is being typed on?
Because this is a Python client-server program, I saw the curses
module, but I'm not sure whether this is the right approach or whether this could solve my problem. Is there a way to have a lock on the Terminal screen maybe?