appyter.ext.socketio package

Submodules

appyter.ext.socketio.chunked_emit module

class appyter.ext.socketio.chunked_emit.ChunkedEmitMixin[source]

Bases: object

A mixin for splitting up large emit calls into chunked calls of lower priority

CHUNK_SIZE = 1048576
async emit(evt, data, priority=0, **kwargs)[source]

appyter.ext.socketio.client module

class appyter.ext.socketio.client.AsyncClient(reconnection=True, reconnection_attempts=0, reconnection_delay=1, reconnection_delay_max=5, randomization_factor=0.5, logger=False, json=None, **kwargs)[source]

Bases: appyter.ext.socketio.chunked_emit.ChunkedEmitMixin, appyter.ext.socketio.forwarding.ForwardingMixin, appyter.ext.socketio.priority_queued_emit.PriorityQueuedEmitMixin, socketio.asyncio_client.AsyncClient

Client with packet forwarding, emit buffering & chunking async with is necessary for initialization

async connect(*args, headers={}, **kwargs)[source]

Connect to a Socket.IO server.

Parameters:

url – The URL of the Socket.IO server. It can include custom

query string parameters if required by the server. :param headers: A dictionary with custom headers to send with the connection request. :param transports: The list of allowed transports. Valid transports are 'polling' and 'websocket'. If not given, the polling transport is connected first, then an upgrade to websocket is attempted. :param namespaces: The namespaces to connect as a string or list of strings. If not given, the namespaces that have registered event handlers are connected. :param socketio_path: The endpoint where the Socket.IO server is installed. The default value is appropriate for most cases.

Note: this method is a coroutine.

Note: The connection mechannism occurs in the background and will complete at some point after this function returns. The connection will be established when the connect event is invoked.

Example usage:

.. code::

sio = socketio.AsyncClient() sio.connect(’http://localhost:5000’)

appyter.ext.socketio.forwarding module

class appyter.ext.socketio.forwarding.ForwardingMixin[source]

Bases: object

A mixin for converting to= messages on the client to forward events to be handled by the server

async emit(evt, data, to=None, priority=0, **kwargs)[source]

appyter.ext.socketio.priority_queued_emit module

class appyter.ext.socketio.priority_queued_emit.PriorityQueuedEmitMixin[source]

Bases: object

A mixin for queuing emit calls to get triggered sequentially when emit_enabled event is set

async disconnect()[source]
async emit(evt, data, priority=0, **kwargs)[source]

appyter.ext.socketio.server module

class appyter.ext.socketio.server.AsyncServer(*args, **kwargs)[source]

Bases: appyter.ext.socketio.chunked_emit.ChunkedEmitMixin, appyter.ext.socketio.priority_queued_emit.PriorityQueuedEmitMixin, socketio.asyncio_server.AsyncServer

Server with packet forwarding. async with is necessary for initialization

async forward(sid, data)[source]
on(event)[source]

Register an event handler.

Parameters:

event – The event name. It can be any string. The event names

'connect', 'message' and 'disconnect' are reserved and should not be used. :param handler: The function that should be invoked to handle the event. When this parameter is not given, the method acts as a decorator for the handler function. :param namespace: The Socket.IO namespace for the event. If this argument is omitted the handler is associated with the default namespace.

Example usage:

.. code::

# as a decorator: @socket_io.on(‘connect’, namespace=’/chat’) def connect_handler(sid, environ):

print(‘Connection request’) if environ[‘REMOTE_ADDR’] in blacklisted:

return False # reject

# as a method: def message_handler(sid, msg):

print(‘Received message: ‘, msg) eio.send(sid, ‘response’)

socket_io.on(‘message’, namespace=’/chat’, handler=message_handler)

The handler function receives the sid (session ID) for the client as first argument. The 'connect' event handler receives the WSGI environment as a second argument, and can return False to reject the connection. The 'message' handler and handlers for custom event names receive the message payload as a second argument. Any values returned from a message handler will be passed to the client’s acknowledgement callback function if it exists. The 'disconnect' handler does not take a second argument.

Module contents