I have the typical Chat aplication.
The Client side is implemented using two Threads.
Thread1
do {
show menu
read option
case option
1: option1
2: option2
.
.
.
5:end
end case
while (!end)
Thread 2:
do {
read message from socket
display message
while (!end)
One problem is the Thread1 being to fast, so after procesing the option it displays the menu again before the Thread2 can display it's message. I have solve this by puting Thread1 to sleep for 1000ms, but don't know if there is a better way to do this.
The other one is: when a client is doing nothing, there is just a message on screen asking for a option to process. If another Client send him a message, then this message displays after the promt, so the info is messy: here is an example of what a Client will see after getting a message from another client.
1.- Print users conected
2.- Send message to all
3.- Send message to a user
4.- Quit
Choose an option: Message received from user "david": hello!
Is there any way to deal with this?