Difficulties displaying text in a simple client / server chat program (current input is displayed) - C

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. , , .

, / ? , ?

. .

+3
5

, curses , , .

+4

unix, , , stdin/stdout.

, ( ) - . .

, , :

http://www.greenteapress.com/semaphores/

+1

- , ( ). C? ( Java).

0

. , , "". : ( ), - .

C , . . , .

0

, , . , , , .

Otherwise, your best bet will use curses, as suggested. A scroll window (3x) can be used as a terminal easily using waddstr (3x) and wgetnstr (3x), there is no need for a micro manager if you use an IRC-like interface.

Note that using curses does not mean that you do not need to use a mutex around your curses functions. Otherwise, when you are less likely to expect garbage to appear on the screen.

0
source

Source: https://habr.com/ru/post/1729143/


All Articles