Implemented select() to watch for events on stdin and socket descriptors