MESSAGE
DATE | 2005-02-11 |
FROM | Billy
|
SUBJECT | Re: [hangout] Monitoring input in simple chat exercise.
|
Martin, Jared wrote: > I'm working on creating a simple chat program to get my feet wet in c. > > I've been told its better to avoid threads, so I'm using select to monitor > multiple connections from clients. > > How do I get the client to check for new data on both the network conn as > well as input from the user without having one block the other? > Should I use select on the client too or is there a better way of doing it. > > Perhaps recv with peek would work to check the socket, but I've not yet > figured out how to receive input from the user without blocking and without > checking for individual keystrokes. > > Suggestions/Links/Code would be very greatly appreciated.
select will do it, but you probably also need to configure the terminal. You will have to use tcsetattr to setup.
You need to clear the ICANON and ECHO cflag, You can to set c_cc[VMIN]=1 and c_cc[VTIME]=0.
It's all explained here: http://www.delorie.com/gnu/docs/glibc/libc_372.html
Your client program will probably work best as a loop doing select() on both the input terminal and the server connection socket. ____________________________ NYLXS: New Yorker Free Software Users Scene Fair Use - because it's either fair use or useless.... NYLXS is a trademark of NYLXS, Inc
|
|