TcpSocket refactoring