async def transport_provider(): try: client_connection = await asyncio.open_connection('localhost', port) yield TransportTCP(*client_connection) yield FailingTransport() client_connection = await asyncio.open_connection('localhost', port) yield TransportTCP(*client_connection) except Exception: logger().error('Client connection error', exc_info=True) raise
def session(*connection): container.transport = TransportTCP(*connection) container.server = RSocketServer(container.transport, IdentifiedHandlerFactory(next(index_iterator), ServerHandler, delay=timedelta(seconds=1)).factory) waiter.set()
async def transport_provider(): while True: try: nonlocal client_connection client_connection = await asyncio.open_connection(host, port) yield TransportTCP(*client_connection) except Exception: logger().error('Client connection error', exc_info=True) raise
async def transport_provider(): try: for i in range(3): client_connection = await asyncio.open_connection( 'localhost', unused_tcp_port) yield TransportTCP(*client_connection) except Exception: logger().error('Client connection error', exc_info=True) raise
async def start(): nonlocal service, client service = await asyncio.start_server(session, host, port) connection = await asyncio.open_connection(host, port) nonlocal client_arguments # test_overrides = {'keep_alive_period': timedelta(minutes=20)} client_arguments = client_arguments or {} # client_arguments.update(test_overrides) client = RSocketClient(single_transport_provider(TransportTCP(*connection)), **(client_arguments or {})) if auto_connect_client: await client.connect()
async def main(): connection = await asyncio.open_connection('localhost', 7000) setup_payload = Payload(data=str(uuid4()).encode(), metadata=composite( route('shell-client'), authenticate_simple('user', 'pass'))) async with RSocketClient(single_transport_provider( TransportTCP(*connection)), setup_payload=setup_payload, metadata_encoding=WellKnownMimeTypes. MESSAGE_RSOCKET_COMPOSITE_METADATA): await asyncio.sleep(5)
async def main(server_port): logging.info('Connecting to server at localhost:%s', server_port) connection = await asyncio.open_connection('localhost', server_port) async with RSocketClient(single_transport_provider( TransportTCP(*connection)), metadata_encoding=WellKnownMimeTypes. MESSAGE_RSOCKET_COMPOSITE_METADATA) as client: await request_response(client) await request_stream(client) await request_slow_stream(client) await request_channel(client) await request_stream_invalid_login(client) await request_fragmented_stream(client)
async def main(server_port): completion_event = Event() class Subscriber(DefaultSubscriber): def __init__(self): super().__init__() self.values = [] self.subscription: Optional[Subscription] = None def on_next(self, value, is_complete=False): self.values.append(value) self.subscription.request(1) def on_complete(self): completion_event.set() def on_error(self, exception: Exception): completion_event.set() connection = await asyncio.open_connection('localhost', server_port) async with RSocketClient(single_transport_provider( TransportTCP(*connection)), metadata_encoding=WellKnownMimeTypes. MESSAGE_RSOCKET_COMPOSITE_METADATA.value.name, data_encoding=WellKnownMimeTypes.APPLICATION_JSON. value.name) as client: metadata = CompositeMetadata() metadata.append( RoutingMetadata(['investigation.getInvestigationByContext'])) body = json.dumps({'active': True}).encode() request = Payload(body, metadata.serialize()) subscriber = Subscriber() client.request_stream(request).subscribe(subscriber) await completion_event.wait() await asyncio.sleep(4) # Used to show keepalive is working assert len(subscriber.values) == 2
async def main(server_port): logging.info('Connecting to server at localhost:%s', server_port) connection = await asyncio.open_connection('localhost', server_port) async with RSocketClient(single_transport_provider( TransportTCP(*connection)), metadata_encoding=WellKnownMimeTypes. MESSAGE_RSOCKET_COMPOSITE_METADATA) as client: rx_client = RxRSocket(client) await request_response(rx_client) await request_stream(rx_client) await request_slow_stream(rx_client) await request_channel(rx_client) await request_stream_invalid_login(rx_client) await request_fragmented_stream(rx_client) await metadata_push(rx_client, b'audit info') await request_last_metadata(rx_client) await fire_and_forget(rx_client, b'aux data') await request_last_fnf(rx_client)
async def main(server_port): logging.info('Connecting to server at localhost:%s', server_port) connection = await asyncio.open_connection('localhost', server_port) async with RSocketClient( single_transport_provider(TransportTCP(*connection))) as client: payload = Payload(b'%Y-%m-%d %H:%M:%S') async def run_request_response(): try: while True: result = await client.request_response(payload) logging.info('Response: {}'.format(result.data)) await asyncio.sleep(1) except asyncio.CancelledError: pass task = asyncio.create_task(run_request_response()) await asyncio.sleep(5) task.cancel() await task
def session(*connection): nonlocal server server = RSocketServer(TransportTCP(*connection), **(server_arguments or {})) wait_for_server.set()
def handle_client(reader, writer): RSocketServer(TransportTCP(reader, writer), handler_factory=handler_factory)
def session(*connection): RSocketServer(TransportTCP(*connection), handler_factory=Handler)
def session(*connection): nonlocal server, transport transport = TransportTCP(*connection) server = RSocketServer(transport, IdentifiedHandlerFactory(next(index_iterator), ServerHandler).factory) wait_for_server.set()
async def transport_provider(max_reconnect): for i in range(max_reconnect): connection = await asyncio.open_connection('localhost', server_port) yield TransportTCP(*connection)
def handle_client(reader, writer): RSocketServer(TransportTCP(reader, writer), handler_factory=handler_factory, lease_publisher=SingleLeasePublisher( maximum_request_count=5, maximum_lease_time=timedelta(seconds=2)))