def _client_and_server(self, port): server = TCPServer(LOCAL_IP, port) client = TCPClient() try: yield client, server finally: server.close() client.close()
def _tcp_server_and_client(self, server_port, client_port=None, timeout=None): server = TCPServer(LOCAL_IP, server_port, timeout=timeout) client = TCPClient(timeout=timeout) if client_port: client.set_own_ip_and_port(LOCAL_IP, client_port) client.connect_to(LOCAL_IP, server_port) self.sockets.append(server) self.sockets.append(client) return server, client
def test_tcp_server_with_named_connection(self): server = TCPServer(LOCAL_IP, 1337) TCPClient().connect_to(LOCAL_IP, 1337) server.accept_connection(alias=CONNECTION_ALIAS + "1") self.assertTrue(server._connections.get(CONNECTION_ALIAS + "1"))
def test_tcp_server_with_no_connections(self): server = TCPServer(LOCAL_IP, 1338) client = TCPClient() client.connect_to(LOCAL_IP, 1338) client.send('foofaa'.encode()) self.assertRaises(AssertionError, server.receive)
def _tcp_server(self, server_port, timeout=20): server = TCPServer(LOCAL_IP, server_port, timeout=timeout) self.sockets.append(server) return server