async def download(reader, writer): socket = RSocket(reader, writer, server=False) payload = Payload(b'The quick brown fox', b'meta') print('RR: {}'.format(await socket.request_response(payload))) socket.request_stream(payload).subscribe(StreamSubscriber()) await asyncio.sleep(0.1) await socket.close() return payload
async def connect(self): """Used to connect to Elarian.""" self._request_handler.handle("pending") setup = AppConnectionMetadata() setup.org_id = self._org_id setup.app_id = self._app_id setup.api_key.value = self._api_key setup.simplex_mode = not self._options['allow_notifications'] setup.simulator_mode = self._is_simulator self._loop = asyncio.get_event_loop() self._connection = await asyncio.open_connection( host='tcp.elarian.dev', loop=self._loop, port=8082, ssl=ssl.create_default_context(), server_hostname='tcp.elarian.dev', ) self._socket = RSocket( reader=self._connection[0], writer=self._connection[1], server=False, loop=self._loop, data_encoding=b'application/octet-stream', metadata_encoding=b'application/octet-stream', setup_payload=Payload(data=setup.SerializeToString()), keep_alive_milliseconds=self._options['keep_alive'], max_lifetime_milliseconds=self._options['lifetime'], handler_factory=self._make_request_handler, error_handler=self._error_handler) self._is_connected = True self._loop.create_task(self.__keep_running()) self._request_handler.handle("connected") atexit.register(self.__clean_up) return self
async def download(reader, writer): composite_metadata = CompositeMetadata() composite_metadata.add_custom_metadata("application/info", b'{"id":1}') socket = RSocket( reader, writer, server=False, data_encoding=b'text/plain', metadata_encoding=b'message/x.rsocket.composite-metadata.v0', setup_payload=Payload(b'', composite_metadata.get_source())) payload = Payload(b'The quick brown fox', b'meta') print('RR: {}'.format(await socket.request_response(payload))) socket.request_stream(payload).subscribe(StreamSubscriber()) socket.fire_and_forget(Payload(b'fire_and_forget request', b'meta')) await asyncio.sleep(1.0) await socket.close() return payload
def session(reader, writer): RSocket(reader, writer, handler_factory=Handler)
def session(reader, writer): nonlocal server server = RSocket(reader, writer)
async def start(): nonlocal service, client service = await asyncio.start_server(session, host, port) connection = await asyncio.open_connection(host, port) client = RSocket(*connection, server=False)