To build a chat, I have to send and receive messages.
Currently, I am sending and receiving messages from the command line.
When I receive a message while I was typing one, the received message is printed and I can't see what was typed before. I use the read()
command to catch the user input.
Here is an example:
Let's suppose I want to send the message Hello World
and that I receive a message after typing Hello Wor
.
This is what happens :
$ Enter your message : Hello Wor
$ Somebody: This is a message
$ Enter your message :
But Hello Wor
is still on the command line: if I press the Delete Key, I will see Hello Wo
.
This is what I want :
$ Enter your message : Hello Wor
$ Somebody: This is a message
$ Enter your message : Hello Wor
I would like to save what was typed before printing the received message and print it.