Refactoring socket: moved some functions out to a separate tcp socket module