move sockets code to its own module