# Exceptions

exception aiorpcx.ConnectionError

  When a connection is lost that has pending requests, this exception is set on those requests.

## Server

A simple wrapper around an `asyncio.Server` object (see asyncio.Server).

class aiorpcx.Server(protocol_factory, host=None, port=None, *, loop=None, **kwargs)

  Creates a server that listens for connections on host and port. The server does not actually start listening until `listen()` is await-ed.

  protocol_factory is any callable returning an `asyncio.Protocol` instance. You might find returning an instance of `ServerSession`, or a class derived from it, more useful.

  loop is the event loop to use, or `asyncio.get_event_loop()` if `None`.

  kwargs are passed through to loop.create_server().

  A server instance has the following attributes:

  loop

    The event loop being used.

  host

    The host passed to the constructor

  port

    The port passed to the constructor

  server

    The underlying `asyncio.Server` object when the server is listening, otherwise `None`.

  listen()

    Start listening for incoming connections. Return an `asyncio.Server` instance, which can also be accessed via `server`.

    This method is a coroutine.

  close()

    Close the listening socket if the server is listening, and wait for it to close. Return immediately if the server is not listening.

    This does nothing to protocols and transports handling existing connections. On return `server` is `None`.

  wait_closed()

    Returns when the server has closed.

    This method is a coroutine.

## Sessions

Convenience classes are provided for client and server sessions.

class aiorpcx.ClientSession(host, port, *, rpc_protocol=None, framer=None, scheduler=None, loop=None, proxy=None, **kwargs)

  An instance of an `asyncio.Protocol` class that represents an RPC session with a remote server at host and port, as documented in loop.create_connection().`

  If proxy is not given, `create_connection()` uses `loop.create_connection()` to attempt a connection, otherwise `SOCKSProxy.create_connection()`. You can pass additional arguments to those functions with kwargs (host and port and loop are used as given).

  rpc_protocol specifies the RPC protocol the server speaks. If `None` the protocol returned by `default_rpc_protocol()` is used.

  framer handles RPC message framing, and if `None` then the framer returned by `default_framer()` is used.

  scheduler should be left as `None`.

  Logging will be sent to logger, `None` will use a logger specific to the `ClientSession` object’s class.

  create_connection()

    Make a connection attempt to the remote server. If successful this return a `(transport, protocol)` pair.

    This method is a coroutine.

  default_rpc_protocol()

    You can override this method to provide a default RPC protocol. `JSONRPCv2` is returned by the default implementation.

  default_framer()

    You can override this method to provide a default message frmaer. A new `NewlineFramer` instance is returned by the default implementation.

The `ClientSession` and `ServerSession` classes share a base class that has the following attributes and methods: