コード例 #1
0
 def _client_and_server(self, port):
     server = TCPServer(LOCAL_IP, port)
     client = TCPClient()
     try:
         yield client, server
     finally:
         server.close()
         client.close()
コード例 #2
0
 def _client_and_server(self, port):
     server = TCPServer(LOCAL_IP, port)
     client = TCPClient()
     try:
         yield client, server
     finally:
         server.close()
         client.close()
コード例 #3
0
 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
コード例 #4
0
 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
コード例 #5
0
 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"))
コード例 #6
0
 def test_tcp_server_with_queued_connections(self):
     server, client = self._tcp_server_and_client(ports['SERVER_PORT'])
     TCPClient().connect_to(LOCAL_IP, ports['SERVER_PORT'])
     server.accept_connection()
     server.accept_connection()
コード例 #7
0
 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)
コード例 #8
0
 def test_tcp_server_with_no_connections(self):
     server = TCPServer(LOCAL_IP, 1337)
     client = TCPClient()
     client.connect_to(LOCAL_IP, 1337)
     client.send('foofaa')
     self.assertRaises(AssertionError, server.receive)