If you want to stick with the select-loop monolithic model (a very noble goal, but very difficult if you don't already know how sockets work), you need to place the socket in a non-blocking mode, and basically do everything that stdio is doing for you (behind the scenes, blocking): input/output buffers, checking for time-out conditions, etc. Unfortunately I don't know of a module that provides these basic functions for you (which would make writing apps of this nature infinitely easier for the novice).