async def handle(self, connection: ConnectionAPI, cmd: Ping) -> None: connection.logger.debug2("Received ping on %s, replying with pong", connection) try: connection.get_base_protocol().send(Pong(None)) except PeerConnectionLost: connection.logger.debug2("%s disconnected while sending pong", connection)
async def do_ping_pong_test(alice_connection: ConnectionAPI, bob_connection: ConnectionAPI) -> None: got_ping = asyncio.Event() got_pong = asyncio.Event() async def _handle_ping(connection: ConnectionAPI, msg: Any) -> None: got_ping.set() bob_connection.get_base_protocol().send_pong() async def _handle_pong(connection: ConnectionAPI, msg: Any) -> None: got_pong.set() alice_connection.add_command_handler(Pong, _handle_pong) bob_connection.add_command_handler(Ping, _handle_ping) alice_connection.get_base_protocol().send_ping() await asyncio.wait_for(got_ping.wait(), timeout=1) await asyncio.wait_for(got_pong.wait(), timeout=1)
def _send_ping(connection: ConnectionAPI) -> None: connection.get_base_protocol().send(Ping(None))
async def handle(self, connection: ConnectionAPI, cmd: Ping) -> None: connection.logger.debug2("Received ping on %s, replying with pong", connection) connection.get_base_protocol().send(Pong(None))
async def handle(self, connection: ConnectionAPI, msg: Payload) -> None: connection.get_base_protocol().send_pong()
async def handle(self, connection: ConnectionAPI, cmd: Ping) -> None: connection.get_base_protocol().send(Pong(None))