protocol

class async_patterns.protocol.Protocol(loop)[source]

Derives asyncio.Protocol. Interprets incoming and outgoing data as object instances satisfying the packet protocol (see below). Schedules execution of the packet call function for incoming packets.

A unique id is added to outgoing packets. A future is also created for each outgoing packet. The receiving end can construct a packet and set the response_to attribute to this id and send the new packet back to this protocol. This protocol will see the response_to attribute and assign the response packet as the result of the future.

packet protocol

class Packet:
    async def __call__(self, protocol):
        # protocol is this instance
        pass
close()[source]

This method is a coroutine.

connection_lost(exc)[source]

Called when the connection is lost or closed.

The argument is an exception object or None (the latter meaning a regular EOF is received or the connection was aborted or closed).

connection_made(transport)[source]

Called when a connection is made.

The argument is the transport representing the pipe connection. To receive data, wait for data_received() calls. When the connection is closed, connection_lost() is called.

data_received(data)[source]

Called when some data is received.

The argument is a bytes object.

write(packet)[source]

Write an object to the socket. Assign the object a message_id before sending.

Parameters:packet – object to pickle and send
Return type:future