views:

137

answers:

2

I got an assessment to write a simple chat client for Linux using ncurses. The chat has two windows: one displays what the other client says, the other handles user input.

What confuses me here is how to handle data that constantly comes from the socket and waits for the user's input at the same time. The only one solution that comes into my mind is to use pthreads, but I have a feeling that I'm missing something more appropriate.

Any suggestions?

+8  A: 

You can take a look at the select(2) system call and read about multiplexing IO.

Jason Coco
A: 

Use two proceses - one reads user input, one writes data coming from the socket. Use the fork() system call to create the second process.

anon