Modularized reading from the socket. Added loop for selecting sockets.