You can use a thread running as your receiver and have it check every interval if the socket is readible. If it is, you can receive data and process it accordingly. All of your sending can be done in a blocking manner. To illustrate:
Code:
void ReceiveThread(void *pSomething) {
while (socket is good) {
if (socket is readible) {
receive(some data);
if (it is a chat message)
print(the chat message on the screen);
}
}
}
int main() {
connect(to a server);
start(your ReceiveThread);
read (some text from keyboard);
send(some text to server);
return 0;
}
Something along those lines. Keep in mind, of course, that this is a very simplistic pseudocode view from the top of a really tall ladder and there are many other details that must be taken into consideration. But this is a general structure that should do the job for you.