I am writing a program for a LAN chat in C. For a chat application we need to receive the clints chat as soon as he sends it. But the problem is that i used the gets() function to input the chat from one side and while the gets is running, if a chat comes from the other end, it won't be received till I send a chat to the other end. Here is the code I used for sending and receiving the chat in the server side. I have removed all the conditions that i used because they all proved worthless. Please tell me an way to display the chat from the other end as soon as it is send, regardless of which statement is currently executed. Thanks in advance. Here is my present code of the sending and receiving part:
while(1)
{
printf("\n");
gets(send_data);
send(connected, send_data,strlen(send_data), 0);
bytes_recieved = recv(connected,recv_data,1024,0);
recv_data[bytes_recieved] = '\0';
printf("Client Says: %s " , recv_data);
fflush(stdout);
}