loop until key press (C code)

I am writing a client/server program in plain C i have the server working fine but i am having a bit of trouble with the client. I want the client to be in an infinite loop of reading from the server until a key is pressed or sent (to keep the conversation refreshing while not typing instead of halting waiting for input every pass)

i have tried a few different things and none have worked.. here is the basic idea i want.. any ideas? i read about kbhit and getch neither work on my compiler (gcc)

1
2
3
4
5
6
7
8
9
10
11
12
13
while (1)
{
   read(fd, buf, sizeof buf); /*reading from server*/
   if (key pressed/sent)
   {
      /*need a wayy o get message stored to send in write()
       * i was thinking something like this*/
      fgets(message, sizeof(message), stdin); 
      write(fd, message, sizeof message); 
   }
   /*there will be code here to ensure the client is
    * not printing the same message over and over */
}


thanks in advance.
http://linux.die.net/man/2/poll

Poll on both the server and the standard input, and respond appropriately depending on which is the sender.

Hope this helps.
Topic archived. No new replies allowed.