in reply to socket reading...

You may want to read up on using timeout with the select() function. But definately read up on non-blocking. Here's a pretty good reference (Unix wise): Unix Socket FAQ