views:

89

answers:

1

I'm newbie.

I want to make the client program to receive input from keyboard and data from server. I don't want if while user type something (scanf) and its block to receive data from server.

How to write the code in C ?

Thank you.

+1  A: 

Welcome :)

I suggest grabbing a copy of Advanced Programming in the Unix Environment, 2nd Edition as soon as you can. It has excellent examples on using select() (and everything else, too).

The source code package on the page above includes an excellent example, calld/loop.c that shows more or less exactly what you want -- a server loop that accepts connections, adds the connections to the select mask of file descriptors, and handles file descriptors in turn.

If you'd like a friendlier interface, investigate libevent. Libevent can give you higher performance on a wide range of platforms and a nice interface. Great for production code, maybe less great for learning how the kernel works.

sarnold
Maybe add Beej's guide ( http://beej.us/guide/bgnet/ ) as a quickly accessible, free resource?
Jack Kelly