I am writing a chat program for my network class, and I have all the network settings.
My problem is that the client is currently writing a message, and he is receiving a message from another client, then his current input will be displayed with the received message.
For example, if a client writes the message "Hello, how are you?" and receives the message "Good afternoon!" while in the middle of writing their message, it appears as:
Hello good day!
-> w are you?
Where → is the area for the user to enter a message. What I would like is to simply display the received message and have an area → save all the previous text that was written before the message was received.
Please note that what the client dials is still actually there when he receives the message. If he completes his message, his full message will be sent.
Also note that my client uses pthreads. One stream for reading messages from the server and displaying them on the user's screen and one stream for reading from stdin and sending messages to the server. I really believe that my problem arises from the fact that I use pthreads and the threads share the same stdin, stdout, stderr. Maybe this is a misconception and a misconception?
, . , . , , .
:
, , , . -, , , , "" / stdin. , , .
, / ? , ?
. .