socketio API Reference
Full documentation for socketio (Standard Library / Native)
socketio.ASGIApp
Python Library Documentation: class ASGIApp in module socketio.asgi
class ASGIApp(engineio.async_drivers.asgi.ASGIApp)
| ASGIApp(socketio_server, other_asgi_app=None, static_files=None, socketio_path='socket.io', on_startup=None, on_shutdown=None)
|
| ASGI application middleware for Socket.IO.
|
| This middleware dispatches traffic to an Socket.IO application. It can
| also serve a list of static files to the client, or forward unrelated
| HTTP traffic to another ASGI application.
|
| :param socketio_server: The Socket.IO server. Must be an instance of the
| ``socketio.AsyncServer`` class.
| :param static_files: A dictionary with static file mapping rules. See the
| documentation for details on this argument.
| :param other_asgi_app: A separate ASGI app that receives all other traffic.
| :param socketio_path: The endpoint where the Socket.IO application should
| be installed. The default value is appropriate for
| most cases. With a value of ``None``, all incoming
| traffic is directed to the Socket.IO server, with the
| assumption that routing, if necessary, is handled by
| a different layer. When this option is set to
| ``None``, ``static_files`` and ``other_asgi_app`` are
| ignored.
| :param on_startup: function to be called on application startup; can be
| coroutine
| :param on_shutdown: function to be called on application shutdown; can be
| coroutine
|
| Example usage::
|
| import socketio
| import uvicorn
|
| sio = socketio.AsyncServer()
| app = socketio.ASGIApp(sio, static_files={
| '/': 'index.html',
| '/static': './public',
| })
| uvicorn.run(app, host='127.0.0.1', port=5000)
|
| Method resolution order:
| ASGIApp
| engineio.async_drivers.asgi.ASGIApp
| builtins.object
|
| Methods defined here:
|
| __init__(self, socketio_server, other_asgi_app=None, static_files=None, socketio_path='socket.io', on_startup=None, on_shutdown=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from engineio.async_drivers.asgi.ASGIApp:
|
| async __call__(self, scope, receive, send)
| Call self as a function.
|
| async lifespan(self, scope, receive, send)
|
| async not_found(self, receive, send)
| Return a 404 Not Found error to the client.
|
| async serve_static_file(self, static_file, receive, send)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from engineio.async_drivers.asgi.ASGIApp:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
socketio.AsyncAioPikaManager
Python Library Documentation: class AsyncAioPikaManager in module socketio.async_aiopika_manager class AsyncAioPikaManager(socketio.async_pubsub_manager.AsyncPubSubManager) | AsyncAioPikaManager(url='amqp://guest:guest@localhost:5672//', channel='socketio', write_only=False, logger=None, json=None) | | Client manager that uses aio_pika for inter-process messaging under | asyncio. | | This class implements a client manager backend for event sharing across | multiple processes, using RabbitMQ | | To use a aio_pika backend, initialize the :class:`Server` instance as | follows:: | | url = 'amqp://user:password@hostname:port//' | server = socketio.Server(client_manager=socketio.AsyncAioPikaManager( | url)) | | :param url: The connection URL for the backend messaging queue. Example | connection URLs are ``'amqp://guest:guest@localhost:5672//'`` | for RabbitMQ. | :param channel: The channel name on which the server sends and receives | notifications. Must be the same in all the servers. | With this manager, the channel name is the exchange name | in rabbitmq | :param write_only: If set to ``True``, only initialize to emit events. The | default of ``False`` initializes the class for emitting | and receiving. A write-only instance can be used | independently of the server to emit to clients from an | external process. | :param logger: a custom logger to log it. If not given, the server logger | is used. | :param json: An alternative JSON module to use for encoding and decoding | packets. Custom json modules must have ``dumps`` and ``loads`` | functions that are compatible with the standard library | versions. This setting is only used when ``write_only`` is set | to ``True``. Otherwise the JSON module configured in the | server is used. | | Method resolution order: | AsyncAioPikaManager | socketio.async_pubsub_manager.AsyncPubSubManager | socketio.async_manager.AsyncManager | socketio.base_manager.BaseManager | builtins.object | | Methods defined here: | | __init__(self, url='amqp://guest:guest@localhost:5672//', channel='socketio', write_only=False, logger=None, json=None) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | name = 'asyncaiopika' | | ---------------------------------------------------------------------- | Methods inherited from socketio.async_pubsub_manager.AsyncPubSubManager: | | async can_disconnect(self, sid, namespace) | | async close_room(self, room, namespace=None) | Remove all participants from a room. | | Note: this method is a coroutine. | | async disconnect(self, sid, namespace, **kwargs) | Disconnect a client. | | Note: this method is a coroutine. | | async emit(self, event, data, namespace=None, room=None, skip_sid=None, callback=None, to=None, **kwargs) | Emit a message to a single client, a room, or all the clients | connected to the namespace. | | This method takes care or propagating the message to all the servers | that are connected through the message queue. | | The parameters are the same as in :meth:`.Server.emit`. | | Note: this method is a coroutine. | | async enter_room(self, sid, namespace, room, eio_sid=None) | Add a client to a room. | | Note: this method is a coroutine. | | initialize(self) | Invoked before the first request is received. Subclasses can add | their initialization code here. | | async leave_room(self, sid, namespace, room) | Remove a client from a room. | | Note: this method is a coroutine. | | ---------------------------------------------------------------------- | Methods inherited from socketio.async_manager.AsyncManager: | | async connect(self, eio_sid, namespace) | Register a client connection to a namespace. | | Note: this method is a coroutine. | | async trigger_callback(self, sid, id, data) | Invoke an application callback. | | Note: this method is a coroutine. | | ---------------------------------------------------------------------- | Methods inherited from socketio.base_manager.BaseManager: | | basic_close_room(self, room, namespace) | | basic_disconnect(self, sid, namespace, **kwargs) | | basic_enter_room(self, sid, namespace, room, eio_sid=None) | | basic_leave_room(self, sid, namespace, room) | | eio_sid_from_sid(self, sid, namespace) | | get_namespaces(self) | Return an iterable with the active namespace names. | | get_participants(self, namespace, room) | Return an iterable with the active participants in a room. | | Note that in a multi-server scenario this method only returns the | participants connect to the server in which the method is called. There | is currently no functionality to assemble a complete list of users | across multiple servers. | | get_rooms(self, sid, namespace) | Return the rooms a client is in. | | is_connected(self, sid, namespace) | | pre_disconnect(self, sid, namespace) | Put the client in the to-be-disconnected list. | | This allows the client data structures to be present while the | disconnect handler is invoked, but still recognize the fact that the | client is soon going away. | | set_server(self, server) | | sid_from_eio_sid(self, eio_sid, namespace) | | ---------------------------------------------------------------------- | Data descriptors inherited from socketio.base_manager.BaseManager: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
socketio.AsyncClient
Python Library Documentation: class AsyncClient in module socketio.async_client
class AsyncClient(socketio.base_client.BaseClient)
| AsyncClient(reconnection=True, reconnection_attempts=0, reconnection_delay=1, reconnection_delay_max=5, randomization_factor=0.5, logger=False, serializer='default', json=None, handle_sigint=True, **kwargs)
|
| A Socket.IO client for asyncio.
|
| This class implements a fully compliant Socket.IO web client with support
| for websocket and long-polling transports.
|
| :param reconnection: ``True`` if the client should automatically attempt to
| reconnect to the server after an interruption, or
| ``False`` to not reconnect. The default is ``True``.
| :param reconnection_attempts: How many reconnection attempts to issue
| before giving up, or 0 for infinite attempts.
| The default is 0.
| :param reconnection_delay: How long to wait in seconds before the first
| reconnection attempt. Each successive attempt
| doubles this delay.
| :param reconnection_delay_max: The maximum delay between reconnection
| attempts.
| :param randomization_factor: Randomization amount for each delay between
| reconnection attempts. The default is 0.5,
| which means that each delay is randomly
| adjusted by +/- 50%.
| :param logger: To enable logging set to ``True`` or pass a logger object to
| use. To disable logging set to ``False``. The default is
| ``False``. Note that fatal errors are logged even when
| ``logger`` is ``False``.
| :param json: An alternative JSON module to use for encoding and decoding
| packets. Custom json modules must have ``dumps`` and ``loads``
| functions that are compatible with the standard library
| versions. This is a process-wide setting, all instantiated
| servers and clients must use the same JSON module.
| :param handle_sigint: Set to ``True`` to automatically handle disconnection
| when the process is interrupted, or to ``False`` to
| leave interrupt handling to the calling application.
| Interrupt handling can only be enabled when the
| client instance is created in the main thread.
|
| The Engine.IO configuration supports the following settings:
|
| :param request_timeout: A timeout in seconds for requests. The default is
| 5 seconds.
| :param http_session: an initialized ``aiohttp.ClientSession`` object to be
| used when sending requests to the server. Use it if
| you need to add special client options such as proxy
| servers, SSL certificates, custom CA bundle, etc.
| :param ssl_verify: ``True`` to verify SSL certificates, or ``False`` to
| skip SSL certificate verification, allowing
| connections to servers with self signed certificates.
| The default is ``True``.
| :param websocket_extra_options: Dictionary containing additional keyword
| arguments passed to
| ``websocket.create_connection()``.
| :param engineio_logger: To enable Engine.IO logging set to ``True`` or pass
| a logger object to use. To disable logging set to
| ``False``. The default is ``False``. Note that
| fatal errors are logged even when
| ``engineio_logger`` is ``False``.
|
| Method resolution order:
| AsyncClient
| socketio.base_client.BaseClient
| builtins.object
|
| Methods defined here:
|
| async call(self, event, data=None, namespace=None, timeout=60)
| Emit a custom event to the server and wait for the response.
|
| This method issues an emit with a callback and waits for the callback
| to be invoked before returning. If the callback isn't invoked before
| the timeout, then a ``TimeoutError`` exception is raised. If the
| Socket.IO connection drops during the wait, this method still waits
| until the specified timeout.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used.
| :param data: The data to send to the server. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the event is emitted to the
| default namespace.
| :param timeout: The waiting timeout. If the timeout is reached before
| the server acknowledges the event, then a
| ``TimeoutError`` exception is raised.
|
| Note: this method is not designed to be used concurrently. If multiple
| tasks are emitting at the same time on the same client connection, then
| messages composed of multiple packets may end up being sent in an
| incorrect sequence. Use standard concurrency solutions (such as a Lock
| object) to prevent this situation.
|
| Note 2: this method is a coroutine.
|
| async connect(self, url, headers={}, auth=None, transports=None, namespaces=None, socketio_path='socket.io', wait=True, wait_timeout=1, retry=False)
| Connect to a Socket.IO server.
|
| :param url: The URL of the Socket.IO server. It can include custom
| query string parameters if required by the server. If a
| function is provided, the client will invoke it to obtain
| the URL each time a connection or reconnection is
| attempted.
| :param headers: A dictionary with custom headers to send with the
| connection request. If a function is provided, the
| client will invoke it to obtain the headers dictionary
| each time a connection or reconnection is attempted.
| :param auth: Authentication data passed to the server with the
| connection request, normally a dictionary with one or
| more string key/value pairs. If a function is provided,
| the client will invoke it to obtain the authentication
| data each time a connection or reconnection is attempted.
| :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.
| :param wait: if set to ``True`` (the default) the call only returns
| when all the namespaces are connected. If set to
| ``False``, the call returns as soon as the Engine.IO
| transport is connected, and the namespaces will connect
| in the background.
| :param wait_timeout: How long the client should wait for the
| connection. The default is 1 second. This
| argument is only considered when ``wait`` is set
| to ``True``.
| :param retry: Apply the reconnection logic if the initial connection
| attempt fails. The default is ``False``.
|
| Note: this method is a coroutine.
|
| Example usage::
|
| sio = socketio.AsyncClient()
| await sio.connect('http://localhost:5000')
|
| async disconnect(self)
| Disconnect from the server.
|
| Note: this method is a coroutine.
|
| async emit(self, event, data=None, namespace=None, callback=None)
| Emit a custom event to the server.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used.
| :param data: The data to send to the server. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the event is emitted to the
| default namespace.
| :param callback: If given, this function will be called to acknowledge
| the server has received the message. The arguments
| that will be passed to the function are those provided
| by the server.
|
| Note: this method is not designed to be used concurrently. If multiple
| tasks are emitting at the same time on the same client connection, then
| messages composed of multiple packets may end up being sent in an
| incorrect sequence. Use standard concurrency solutions (such as a Lock
| object) to prevent this situation.
|
| Note 2: this method is a coroutine.
|
| is_asyncio_based(self)
|
| async send(self, data, namespace=None, callback=None)
| Send a message to the server.
|
| This function emits an event with the name ``'message'``. Use
| :func:`emit` to issue custom event names.
|
| :param data: The data to send to the server. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the event is emitted to the
| default namespace.
| :param callback: If given, this function will be called to acknowledge
| the server has received the message. The arguments
| that will be passed to the function are those provided
| by the server.
|
| Note: this method is a coroutine.
|
| async shutdown(self)
| Stop the client.
|
| If the client is connected to a server, it is disconnected. If the
| client is attempting to reconnect to server, the reconnection attempts
| are stopped. If the client is not connected to a server and is not
| attempting to reconnect, then this function does nothing.
|
| async sleep(self, seconds=0)
| Sleep for the requested amount of time using the appropriate async
| model.
|
| This is a utility function that applications can use to put a task to
| sleep without having to worry about using the correct call for the
| selected async mode.
|
| Note: this method is a coroutine.
|
| start_background_task(self, target, *args, **kwargs)
| Start a background task using the appropriate async model.
|
| This is a utility function that applications can use to start a
| background task using the method that is compatible with the
| selected async mode.
|
| :param target: the target function to execute.
| :param args: arguments to pass to the function.
| :param kwargs: keyword arguments to pass to the function.
|
| The return value is a ``asyncio.Task`` object.
|
| async wait(self)
| Wait until the connection with the server ends.
|
| Client applications can use this function to block the main thread
| during the life of the connection.
|
| Note: this method is a coroutine.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.base_client.BaseClient:
|
| __init__(self, reconnection=True, reconnection_attempts=0, reconnection_delay=1, reconnection_delay_max=5, randomization_factor=0.5, logger=False, serializer='default', json=None, handle_sigint=True, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| event(self, *args, **kwargs)
| Decorator to register an event handler.
|
| This is a simplified version of the ``on()`` method that takes the
| event name from the decorated function.
|
| Example usage::
|
| @sio.event
| def my_event(data):
| print('Received data: ', data)
|
| The above example is equivalent to::
|
| @sio.on('my_event')
| def my_event(data):
| print('Received data: ', data)
|
| A custom namespace can be given as an argument to the decorator::
|
| @sio.event(namespace='/test')
| def my_event(data):
| print('Received data: ', data)
|
| get_sid(self, namespace=None)
| Return the ``sid`` associated with a connection.
|
| :param namespace: The Socket.IO namespace. If this argument is omitted
| the handler is associated with the default
| namespace. Note that unlike previous versions, the
| current version of the Socket.IO protocol uses
| different ``sid`` values per namespace.
|
| This method returns the ``sid`` for the requested namespace as a
| string.
|
| on(self, event, handler=None, namespace=None)
| Register an event handler.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used. The ``'*'`` event name
| can be used to define a catch-all event handler.
| :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. A catch-all namespace can be
| defined by passing ``'*'`` as the namespace.
|
| Example usage::
|
| # as a decorator:
| @sio.on('connect')
| def connect_handler():
| print('Connected!')
|
| # as a method:
| def message_handler(msg):
| print('Received message: ', msg)
| sio.send( 'response')
| sio.on('message', message_handler)
|
| The arguments passed to the handler function depend on the event type:
|
| - The ``'connect'`` event handler does not take arguments.
| - The ``'disconnect'`` event handler does not take arguments.
| - The ``'message'`` handler and handlers for custom event names receive
| the message payload as only argument. Any values returned from a
| message handler will be passed to the client's acknowledgement
| callback function if it exists.
| - A catch-all event handler receives the event name as first argument,
| followed by any arguments specific to the event.
| - A catch-all namespace event handler receives the namespace as first
| argument, followed by any arguments specific to the event.
| - A combined catch-all namespace and catch-all event handler receives
| the event name as first argument and the namespace as second
| argument, followed by any arguments specific to the event.
|
| register_namespace(self, namespace_handler)
| Register a namespace handler object.
|
| :param namespace_handler: An instance of a :class:`Namespace`
| subclass that handles all the event traffic
| for a namespace.
|
| transport(self)
| Return the name of the transport used by the client.
|
| The two possible values returned by this function are ``'polling'``
| and ``'websocket'``.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketio.base_client.BaseClient:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketio.base_client.BaseClient:
|
| reason = <class 'engineio.base_client.BaseClient.reason'>
| Disconnection reasons.
|
|
| reserved_events = ['connect', 'connect_error', 'disconnect', '__discon...
socketio.AsyncClientNamespace
Python Library Documentation: class AsyncClientNamespace in module socketio.async_namespace class AsyncClientNamespace(socketio.base_namespace.BaseClientNamespace) | AsyncClientNamespace(namespace=None) | | Base class for asyncio client-side class-based namespaces. | | A class-based namespace is a class that contains all the event handlers | for a Socket.IO namespace. The event handlers are methods of the class | with the prefix ``on_``, such as ``on_connect``, ``on_disconnect``, | ``on_message``, ``on_json``, and so on. These can be regular functions or | coroutines. | | :param namespace: The Socket.IO namespace to be used with all the event | handlers defined in this class. If this argument is | omitted, the default namespace is used. | | Method resolution order: | AsyncClientNamespace | socketio.base_namespace.BaseClientNamespace | socketio.base_namespace.BaseNamespace | builtins.object | | Methods defined here: | | async call(self, event, data=None, namespace=None, timeout=None) | Emit a custom event to the server and wait for the response. | | The only difference with the :func:`socketio.Client.call` method is | that when the ``namespace`` argument is not given the namespace | associated with the class is used. | | async disconnect(self) | Disconnect a client. | | The only difference with the :func:`socketio.Client.disconnect` method | is that when the ``namespace`` argument is not given the namespace | associated with the class is used. | | Note: this method is a coroutine. | | async emit(self, event, data=None, namespace=None, callback=None) | Emit a custom event to the server. | | The only difference with the :func:`socketio.Client.emit` method is | that when the ``namespace`` argument is not given the namespace | associated with the class is used. | | Note: this method is a coroutine. | | is_asyncio_based(self) | | async send(self, data, namespace=None, callback=None) | Send a message to the server. | | The only difference with the :func:`socketio.Client.send` method is | that when the ``namespace`` argument is not given the namespace | associated with the class is used. | | Note: this method is a coroutine. | | async trigger_event(self, event, *args) | Dispatch an event to the proper handler method. | | In the most common usage, this method is not overloaded by subclasses, | as it performs the routing of events to methods. However, this | method can be overridden if special dispatching rules are needed, or if | having a single method that catches all events is desired. | | Note: this method is a coroutine. | | ---------------------------------------------------------------------- | Methods inherited from socketio.base_namespace.BaseClientNamespace: | | __init__(self, namespace=None) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Data descriptors inherited from socketio.base_namespace.BaseNamespace: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
socketio.AsyncManager
Python Library Documentation: class AsyncManager in module socketio.async_manager class AsyncManager(socketio.base_manager.BaseManager) | Manage a client list for an asyncio server. | | Method resolution order: | AsyncManager | socketio.base_manager.BaseManager | builtins.object | | Methods defined here: | | async can_disconnect(self, sid, namespace) | | async close_room(self, room, namespace) | Remove all participants from a room. | | Note: this method is a coroutine. | | async connect(self, eio_sid, namespace) | Register a client connection to a namespace. | | Note: this method is a coroutine. | | async disconnect(self, sid, namespace, **kwargs) | Disconnect a client. | | Note: this method is a coroutine. | | async emit(self, event, data, namespace, room=None, skip_sid=None, callback=None, to=None, **kwargs) | Emit a message to a single client, a room, or all the clients | connected to the namespace. | | Note: this method is a coroutine. | | async enter_room(self, sid, namespace, room, eio_sid=None) | Add a client to a room. | | Note: this method is a coroutine. | | async leave_room(self, sid, namespace, room) | Remove a client from a room. | | Note: this method is a coroutine. | | async trigger_callback(self, sid, id, data) | Invoke an application callback. | | Note: this method is a coroutine. | | ---------------------------------------------------------------------- | Methods inherited from socketio.base_manager.BaseManager: | | __init__(self) | Initialize self. See help(type(self)) for accurate signature. | | basic_close_room(self, room, namespace) | | basic_disconnect(self, sid, namespace, **kwargs) | | basic_enter_room(self, sid, namespace, room, eio_sid=None) | | basic_leave_room(self, sid, namespace, room) | | eio_sid_from_sid(self, sid, namespace) | | get_namespaces(self) | Return an iterable with the active namespace names. | | get_participants(self, namespace, room) | Return an iterable with the active participants in a room. | | Note that in a multi-server scenario this method only returns the | participants connect to the server in which the method is called. There | is currently no functionality to assemble a complete list of users | across multiple servers. | | get_rooms(self, sid, namespace) | Return the rooms a client is in. | | initialize(self) | Invoked before the first request is received. Subclasses can add | their initialization code here. | | is_connected(self, sid, namespace) | | pre_disconnect(self, sid, namespace) | Put the client in the to-be-disconnected list. | | This allows the client data structures to be present while the | disconnect handler is invoked, but still recognize the fact that the | client is soon going away. | | set_server(self, server) | | sid_from_eio_sid(self, eio_sid, namespace) | | ---------------------------------------------------------------------- | Data descriptors inherited from socketio.base_manager.BaseManager: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
socketio.AsyncNamespace
Python Library Documentation: class AsyncNamespace in module socketio.async_namespace class AsyncNamespace(socketio.base_namespace.BaseServerNamespace) | AsyncNamespace(namespace=None) | | Base class for asyncio server-side class-based namespaces. | | A class-based namespace is a class that contains all the event handlers | for a Socket.IO namespace. The event handlers are methods of the class | with the prefix ``on_``, such as ``on_connect``, ``on_disconnect``, | ``on_message``, ``on_json``, and so on. These can be regular functions or | coroutines. | | :param namespace: The Socket.IO namespace to be used with all the event | handlers defined in this class. If this argument is | omitted, the default namespace is used. | | Method resolution order: | AsyncNamespace | socketio.base_namespace.BaseServerNamespace | socketio.base_namespace.BaseNamespace | builtins.object | | Methods defined here: | | async call(self, event, data=None, to=None, sid=None, namespace=None, timeout=None, ignore_queue=False) | Emit a custom event to a client and wait for the response. | | The only difference with the :func:`socketio.Server.call` method is | that when the ``namespace`` argument is not given the namespace | associated with the class is used. | | async close_room(self, room, namespace=None) | Close a room. | | The only difference with the :func:`socketio.Server.close_room` method | is that when the ``namespace`` argument is not given the namespace | associated with the class is used. | | Note: this method is a coroutine. | | async disconnect(self, sid, namespace=None) | Disconnect a client. | | The only difference with the :func:`socketio.Server.disconnect` method | is that when the ``namespace`` argument is not given the namespace | associated with the class is used. | | Note: this method is a coroutine. | | async emit(self, event, data=None, to=None, room=None, skip_sid=None, namespace=None, callback=None, ignore_queue=False) | Emit a custom event to one or more connected clients. | | The only difference with the :func:`socketio.Server.emit` method is | that when the ``namespace`` argument is not given the namespace | associated with the class is used. | | Note: this method is a coroutine. | | async enter_room(self, sid, room, namespace=None) | Enter a room. | | The only difference with the :func:`socketio.Server.enter_room` method | is that when the ``namespace`` argument is not given the namespace | associated with the class is used. | | Note: this method is a coroutine. | | async get_session(self, sid, namespace=None) | Return the user session for a client. | | The only difference with the :func:`socketio.Server.get_session` | method is that when the ``namespace`` argument is not given the | namespace associated with the class is used. | | Note: this method is a coroutine. | | is_asyncio_based(self) | | async leave_room(self, sid, room, namespace=None) | Leave a room. | | The only difference with the :func:`socketio.Server.leave_room` method | is that when the ``namespace`` argument is not given the namespace | associated with the class is used. | | Note: this method is a coroutine. | | async save_session(self, sid, session, namespace=None) | Store the user session for a client. | | The only difference with the :func:`socketio.Server.save_session` | method is that when the ``namespace`` argument is not given the | namespace associated with the class is used. | | Note: this method is a coroutine. | | async send(self, data, to=None, room=None, skip_sid=None, namespace=None, callback=None, ignore_queue=False) | Send a message to one or more connected clients. | | The only difference with the :func:`socketio.Server.send` method is | that when the ``namespace`` argument is not given the namespace | associated with the class is used. | | Note: this method is a coroutine. | | session(self, sid, namespace=None) | Return the user session for a client with context manager syntax. | | The only difference with the :func:`socketio.Server.session` method is | that when the ``namespace`` argument is not given the namespace | associated with the class is used. | | async trigger_event(self, event, *args) | Dispatch an event to the proper handler method. | | In the most common usage, this method is not overloaded by subclasses, | as it performs the routing of events to methods. However, this | method can be overridden if special dispatching rules are needed, or if | having a single method that catches all events is desired. | | Note: this method is a coroutine. | | ---------------------------------------------------------------------- | Methods inherited from socketio.base_namespace.BaseServerNamespace: | | __init__(self, namespace=None) | Initialize self. See help(type(self)) for accurate signature. | | rooms(self, sid, namespace=None) | Return the rooms a client is in. | | The only difference with the :func:`socketio.Server.rooms` method is | that when the ``namespace`` argument is not given the namespace | associated with the class is used. | | ---------------------------------------------------------------------- | Data descriptors inherited from socketio.base_namespace.BaseNamespace: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
socketio.AsyncRedisManager
Python Library Documentation: class AsyncRedisManager in module socketio.async_redis_manager class AsyncRedisManager(socketio.async_pubsub_manager.AsyncPubSubManager) | AsyncRedisManager(url='redis://localhost:6379/0', channel='socketio', write_only=False, logger=None, json=None, redis_options=None) | | Redis based client manager for asyncio servers. | | This class implements a Redis backend for event sharing across multiple | processes. | | To use a Redis backend, initialize the :class:`AsyncServer` instance as | follows:: | | url = 'redis://hostname:port/0' | server = socketio.AsyncServer( | client_manager=socketio.AsyncRedisManager(url)) | | :param url: The connection URL for the Redis server. For a default Redis | store running on the same host, use ``redis://``. To use a | TLS connection, use ``rediss://``. To use Redis Sentinel, use | ``redis+sentinel://`` with a comma-separated list of hosts | and the service name after the db in the URL path. Example: | ``redis+sentinel://user:pw@host1:1234,host2:2345/0/myredis``. | :param channel: The channel name on which the server sends and receives | notifications. Must be the same in all the servers. | :param write_only: If set to ``True``, only initialize to emit events. The | default of ``False`` initializes the class for emitting | and receiving. A write-only instance can be used | independently of the server to emit to clients from an | external process. | :param logger: a custom logger to log it. If not given, the server logger | is used. | :param json: An alternative JSON module to use for encoding and decoding | packets. Custom json modules must have ``dumps`` and ``loads`` | functions that are compatible with the standard library | versions. This setting is only used when ``write_only`` is set | to ``True``. Otherwise the JSON module configured in the | server is used. | :param redis_options: additional keyword arguments to be passed to | ``Redis.from_url()`` or ``Sentinel()``. | | Method resolution order: | AsyncRedisManager | socketio.async_pubsub_manager.AsyncPubSubManager | socketio.async_manager.AsyncManager | socketio.base_manager.BaseManager | builtins.object | | Methods defined here: | | __init__(self, url='redis://localhost:6379/0', channel='socketio', write_only=False, logger=None, json=None, redis_options=None) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | name = 'aioredis' | | ---------------------------------------------------------------------- | Methods inherited from socketio.async_pubsub_manager.AsyncPubSubManager: | | async can_disconnect(self, sid, namespace) | | async close_room(self, room, namespace=None) | Remove all participants from a room. | | Note: this method is a coroutine. | | async disconnect(self, sid, namespace, **kwargs) | Disconnect a client. | | Note: this method is a coroutine. | | async emit(self, event, data, namespace=None, room=None, skip_sid=None, callback=None, to=None, **kwargs) | Emit a message to a single client, a room, or all the clients | connected to the namespace. | | This method takes care or propagating the message to all the servers | that are connected through the message queue. | | The parameters are the same as in :meth:`.Server.emit`. | | Note: this method is a coroutine. | | async enter_room(self, sid, namespace, room, eio_sid=None) | Add a client to a room. | | Note: this method is a coroutine. | | initialize(self) | Invoked before the first request is received. Subclasses can add | their initialization code here. | | async leave_room(self, sid, namespace, room) | Remove a client from a room. | | Note: this method is a coroutine. | | ---------------------------------------------------------------------- | Methods inherited from socketio.async_manager.AsyncManager: | | async connect(self, eio_sid, namespace) | Register a client connection to a namespace. | | Note: this method is a coroutine. | | async trigger_callback(self, sid, id, data) | Invoke an application callback. | | Note: this method is a coroutine. | | ---------------------------------------------------------------------- | Methods inherited from socketio.base_manager.BaseManager: | | basic_close_room(self, room, namespace) | | basic_disconnect(self, sid, namespace, **kwargs) | | basic_enter_room(self, sid, namespace, room, eio_sid=None) | | basic_leave_room(self, sid, namespace, room) | | eio_sid_from_sid(self, sid, namespace) | | get_namespaces(self) | Return an iterable with the active namespace names. | | get_participants(self, namespace, room) | Return an iterable with the active participants in a room. | | Note that in a multi-server scenario this method only returns the | participants connect to the server in which the method is called. There | is currently no functionality to assemble a complete list of users | across multiple servers. | | get_rooms(self, sid, namespace) | Return the rooms a client is in. | | is_connected(self, sid, namespace) | | pre_disconnect(self, sid, namespace) | Put the client in the to-be-disconnected list. | | This allows the client data structures to be present while the | disconnect handler is invoked, but still recognize the fact that the | client is soon going away. | | set_server(self, server) | | sid_from_eio_sid(self, eio_sid, namespace) | | ---------------------------------------------------------------------- | Data descriptors inherited from socketio.base_manager.BaseManager: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
socketio.AsyncServer
Python Library Documentation: class AsyncServer in module socketio.async_server
class AsyncServer(socketio.base_server.BaseServer)
| AsyncServer(client_manager=None, logger=False, json=None, async_handlers=True, namespaces=None, **kwargs)
|
| A Socket.IO server for asyncio.
|
| This class implements a fully compliant Socket.IO web server with support
| for websocket and long-polling transports, compatible with the asyncio
| framework.
|
| :param client_manager: The client manager instance that will manage the
| client list. When this is omitted, the client list
| is stored in an in-memory structure, so the use of
| multiple connected servers is not possible.
| :param logger: To enable logging set to ``True`` or pass a logger object to
| use. To disable logging set to ``False``. Note that fatal
| errors are logged even when ``logger`` is ``False``.
| :param json: An alternative JSON module to use for encoding and decoding
| packets. Custom json modules must have ``dumps`` and ``loads``
| functions that are compatible with the standard library
| versions. This is a process-wide setting, all instantiated
| servers and clients must use the same JSON module.
| :param async_handlers: If set to ``True``, event handlers for a client are
| executed in separate threads. To run handlers for a
| client synchronously, set to ``False``. The default
| is ``True``.
| :param always_connect: When set to ``False``, new connections are
| provisory until the connect handler returns
| something other than ``False``, at which point they
| are accepted. When set to ``True``, connections are
| immediately accepted, and then if the connect
| handler returns ``False`` a disconnect is issued.
| Set to ``True`` if you need to emit events from the
| connect handler and your client is confused when it
| receives events before the connection acceptance.
| In any other case use the default of ``False``.
| :param namespaces: a list of namespaces that are accepted, in addition to
| any namespaces for which handlers have been defined. The
| default is `['/']`, which always accepts connections to
| the default namespace. Set to `'*'` to accept all
| namespaces.
| :param kwargs: Connection parameters for the underlying Engine.IO server.
|
| The Engine.IO configuration supports the following settings:
|
| :param async_mode: The asynchronous model to use. See the Deployment
| section in the documentation for a description of the
| available options. Valid async modes are "aiohttp",
| "sanic", "tornado" and "asgi". If this argument is not
| given, "aiohttp" is tried first, followed by "sanic",
| "tornado", and finally "asgi". The first async mode that
| has all its dependencies installed is the one that is
| chosen.
| :param ping_interval: The interval in seconds at which the server pings
| the client. The default is 25 seconds. For advanced
| control, a two element tuple can be given, where
| the first number is the ping interval and the second
| is a grace period added by the server.
| :param ping_timeout: The time in seconds that the client waits for the
| server to respond before disconnecting. The default
| is 20 seconds.
| :param max_http_buffer_size: The maximum size that is accepted for incoming
| messages. The default is 1,000,000 bytes. In
| spite of its name, the value set in this
| argument is enforced for HTTP long-polling and
| WebSocket connections.
| :param allow_upgrades: Whether to allow transport upgrades or not. The
| default is ``True``.
| :param http_compression: Whether to compress packages when using the
| polling transport. The default is ``True``.
| :param compression_threshold: Only compress messages when their byte size
| is greater than this value. The default is
| 1024 bytes.
| :param cookie: If set to a string, it is the name of the HTTP cookie the
| server sends back to the client containing the client
| session id. If set to a dictionary, the ``'name'`` key
| contains the cookie name and other keys define cookie
| attributes, where the value of each attribute can be a
| string, a callable with no arguments, or a boolean. If set
| to ``None`` (the default), a cookie is not sent to the
| client.
| :param cors_allowed_origins: Origin or list of origins that are allowed to
| connect to this server. Only the same origin
| is allowed by default. Set this argument to
| ``'*'`` to allow all origins, or to ``[]`` to
| disable CORS handling.
| :param cors_credentials: Whether credentials (cookies, authentication) are
| allowed in requests to this server. The default is
| ``True``.
| :param monitor_clients: If set to ``True``, a background task will ensure
| inactive clients are closed. Set to ``False`` to
| disable the monitoring task (not recommended). The
| default is ``True``.
| :param transports: The list of allowed transports. Valid transports
| are ``'polling'`` and ``'websocket'``. Defaults to
| ``['polling', 'websocket']``.
| :param engineio_logger: To enable Engine.IO logging set to ``True`` or pass
| a logger object to use. To disable logging set to
| ``False``. The default is ``False``. Note that
| fatal errors are logged even when
| ``engineio_logger`` is ``False``.
|
| Method resolution order:
| AsyncServer
| socketio.base_server.BaseServer
| builtins.object
|
| Methods defined here:
|
| __init__(self, client_manager=None, logger=False, json=None, async_handlers=True, namespaces=None, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| attach(self, app, socketio_path='socket.io')
| Attach the Socket.IO server to an application.
|
| async call(self, event, data=None, to=None, sid=None, namespace=None, timeout=60, ignore_queue=False)
| Emit a custom event to a client and wait for the response.
|
| This method issues an emit with a callback and waits for the callback
| to be invoked before returning. If the callback isn't invoked before
| the timeout, then a ``TimeoutError`` exception is raised. If the
| Socket.IO connection drops during the wait, this method still waits
| until the specified timeout.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used.
| :param data: The data to send to the client or clients. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
| :param to: The session ID of the recipient client.
| :param sid: Alias for the ``to`` parameter.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the event is emitted to the
| default namespace.
| :param timeout: The waiting timeout. If the timeout is reached before
| the client acknowledges the event, then a
| ``TimeoutError`` exception is raised.
| :param ignore_queue: Only used when a message queue is configured. If
| set to ``True``, the event is emitted to the
| client directly, without going through the queue.
| This is more efficient, but only works when a
| single server process is used. It is recommended
| to always leave this parameter with its default
| value of ``False``.
|
| Note: this method is not designed to be used concurrently. If multiple
| tasks are emitting at the same time to the same client connection, then
| messages composed of multiple packets may end up being sent in an
| incorrect sequence. Use standard concurrency solutions (such as a Lock
| object) to prevent this situation.
|
| Note 2: this method is a coroutine.
|
| async close_room(self, room, namespace=None)
| Close a room.
|
| This function removes all the clients from the given room.
|
| :param room: Room name.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the default namespace is used.
|
| Note: this method is a coroutine.
|
| async disconnect(self, sid, namespace=None, ignore_queue=False)
| Disconnect a client.
|
| :param sid: Session ID of the client.
| :param namespace: The Socket.IO namespace to disconnect. If this
| argument is omitted the default namespace is used.
| :param ignore_queue: Only used when a message queue is configured. If
| set to ``True``, the disconnect is processed
| locally, without broadcasting on the queue. It is
| recommended to always leave this parameter with
| its default value of ``False``.
|
| Note: this method is a coroutine.
|
| async emit(self, event, data=None, to=None, room=None, skip_sid=None, namespace=None, callback=None, ignore_queue=False)
| Emit a custom event to one or more connected clients.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used.
| :param data: The data to send to the client or clients. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
| :param to: The recipient of the message. This can be set to the
| session ID of a client to address only that client, to any
| any custom room created by the application to address all
| the clients in that room, or to a list of custom room
| names. If this argument is omitted the event is broadcasted
| to all connected clients.
| :param room: Alias for the ``to`` parameter.
| :param skip_sid: The session ID of a client to skip when broadcasting
| to a room or to all clients. This can be used to
| prevent a message from being sent to the sender.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the event is emitted to the
| default namespace.
| :param callback: If given, this function will be called to acknowledge
| the client has received the message. The arguments
| that will be passed to the function are those provided
| by the client. Callback functions can only be used
| when addressing an individual client.
| :param ignore_queue: Only used when a message queue is configured. If
| set to ``True``, the event is emitted to the
| clients directly, without going through the queue.
| This is more efficient, but only works when a
| single server process is used. It is recommended
| to always leave this parameter with its default
| value of ``False``.
|
| Note: this method is not designed to be used concurrently. If multiple
| tasks are emitting at the same time to the same client connection, then
| messages composed of multiple packets may end up being sent in an
| incorrect sequence. Use standard concurrency solutions (such as a Lock
| object) to prevent this situation.
|
| Note 2: this method is a coroutine.
|
| async enter_room(self, sid, room, namespace=None)
| Enter a room.
|
| This function adds the client to a room. The :func:`emit` and
| :func:`send` functions can optionally broadcast events to all the
| clients in a room.
|
| :param sid: Session ID of the client.
| :param room: Room name. If the room does not exist it is created.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the default namespace is used.
|
| Note: this method is a coroutine.
|
| async get_session(self, sid, namespace=None)
| Return the user session for a client.
|
| :param sid: The session id of the client.
| :param namespace: The Socket.IO namespace. If this argument is omitted
| the default namespace is used.
|
| The return value is a dictionary. Modifications made to this
| dictionary are not guaranteed to be preserved. If you want to modify
| the user session, use the ``session`` context manager instead.
|
| async handle_request(self, *args, **kwargs)
| Handle an HTTP request from the client.
|
| This is the entry point of the Socket.IO application. This function
| returns the HTTP response body to deliver to the client.
|
| Note: this method is a coroutine.
|
| instrument(self, auth=None, mode='development', read_only=False, server_id=None, namespace='/admin', server_stats_interval=2)
| Instrument the Socket.IO server for monitoring with the `Socket.IO
| Admin UI <https://socket.io/docs/v4/admin-ui/>`_.
|
| :param auth: Authentication credentials for Admin UI access. Set to a
| dictionary with the expected login (usually ``username``
| and ``password``) or a list of dictionaries if more than
| one set of credentials need to be available. For more
| complex authentication methods, set to a callable that
| receives the authentication dictionary as an argument and
| returns ``True`` if the user is allowed or ``False``
| otherwise. To disable authentication, set this argument to
| ``False`` (not recommended, never do this on a production
| server).
| :param mode: The reporting mode. The default is ``'development'``,
| which is best used while debugging, as it may have a
| significant performance effect. Set to ``'production'`` to
| reduce the amount of information that is reported to the
| admin UI.
| :param read_only: If set to ``True``, the admin interface will be
| read-only, with no option to modify room assignments
| or disconnect clients. The default is ``False``.
| :param server_id: The server name to use for this server. If this
| argument is omitted, the server generates its own
| name.
| :param namespace: The Socket.IO namespace to use for the admin
| interface. The default is ``/admin``.
| :param server_stats_interval: The interval in seconds at which the
| server emits a summary of it stats to all
| connected admins.
|
| is_asyncio_based(self)
|
| async leave_room(self, sid, room, namespace=None)
| Leave a room.
|
| This function removes the client from a room.
|
| :param sid: Session ID of the client.
| :param room: Room name.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the default namespace is used.
|
| Note: this method is a coroutine.
|
| async save_session(self, sid, session, namespace=None)
| Store the user session for a client.
|
| :param sid: The session id of the client.
| :param session: The session dictionary.
| :param namespace: The Socket.IO namespace. If this argument is omitted
| the default namespace is used.
|
| async send(self, data, to=None, room=None, skip_sid=None, namespace=None, callback=None, ignore_queue=False)
| Send a message to one or more connected clients.
|
| This function emits an event with the name ``'message'``. Use
| :func:`emit` to issue custom event names.
|
| :param data: The data to send to the client or clients. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
| :param to: The recipient of the message. This can be set to the
| session ID of a client to address only that client, to any
| any custom room created by the application to address all
| the clients in that room, or to a list of custom room
| names. If this argument is omitted the event is broadcasted
| to all connected clients.
| :param room: Alias for the ``to`` parameter.
| :param skip_sid: The session ID of a client to skip when broadcasting
| to a room or to all clients. This can be used to
| prevent a message from being sent to the sender.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the event is emitted to the
| default namespace.
| :param callback: If given, this function will be called to acknowledge
| the client has received the message. The arguments
| that will be passed to the function are those provided
| by the client. Callback functions can only be used
| when addressing an individual client.
| :param ignore_queue: Only used when a message queue is configured. If
| set to ``True``, the event is emitted to the
| clients directly, without going through the queue.
| This is more efficient, but only works when a
| single server process is used. It is recommended
| to always leave this parameter with its default
| value of ``False``.
|
| Note: this method is a coroutine.
|
| session(self, sid, namespace=None)
| Return the user session for a client with context manager syntax.
|
| :param sid: The session id of the client.
|
| This is a context manager that returns the user session dictionary for
| the client. Any changes that are made to this dictionary inside the
| context manager block are saved back to the session. Example usage::
|
| @eio.on('connect')
| async def on_connect(sid, environ):
| username = authenticate_user(environ)
| if not username:
| return False
| async with eio.session(sid) as session:
| session['username'] = username
|
| @eio.on('message')
| async def on_message(sid, msg):
| async with eio.session(sid) as session:
| print('received message from ', session['username'])
|
| async shutdown(self)
| Stop Socket.IO background tasks.
|
| This method stops all background activity initiated by the Socket.IO
| server. It must be called before shutting down the web server.
|
| async sleep(self, seconds=0)
| Sleep for the requested amount of time using the appropriate async
| model.
|
| This is a utility function that applications can use to put a task to
| sleep without having to worry about using the correct call for the
| selected async mode.
|
| Note: this method is a coroutine.
|
| start_background_task(self, target, *args, **kwargs)
| Start a background task using the appropriate async model.
|
| This is a utility function that applications can use to start a
| background task using the method that is compatible with the
| selected async mode.
|
| :param target: the target function to execute. Must be a coroutine.
| :param args: arguments to pass to the function.
| :param kwargs: keyword arguments to pass to the function.
|
| The return value is a ``asyncio.Task`` object.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.base_server.BaseServer:
|
| event(self, *args, **kwargs)
| Decorator to register an event handler.
|
| This is a simplified version of the ``on()`` method that takes the
| event name from the decorated function.
|
| Example usage::
|
| @sio.event
| def my_event(data):
| print('Received data: ', data)
|
| The above example is equivalent to::
|
| @sio.on('my_event')
| def my_event(data):
| print('Received data: ', data)
|
| A custom namespace can be given as an argument to the decorator::
|
| @sio.event(namespace='/test')
| def my_event(data):
| print('Received data: ', data)
|
| get_environ(self, sid, namespace=None)
| Return the WSGI environ dictionary for a client.
|
| :param sid: The session of the client.
| :param namespace: The Socket.IO namespace. If this argument is omitted
| the default namespace is used.
|
| on(self, event, handler=None, namespace=None)
| Register an event handler.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used. The ``'*'`` event name
| can be used to define a catch-all event handler.
| :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. A catch-all namespace can be
| defined by passing ``'*'`` as the namespace.
|
| Example usage::
|
| # as a decorator:
| @sio.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)
| sio.send(sid, 'response')
| socket_io.on('message', namespace='/chat', handler=message_handler)
|
| The arguments passed to the handler function depend on the event type:
|
| - The ``'connect'`` event handler receives the ``sid`` (session ID) for
| the client and the WSGI environment dictionary as arguments.
| - The ``'disconnect'`` handler receives the ``sid`` for the client as
| only argument.
| - The ``'message'`` handler and handlers for custom event names receive
| the ``sid`` for the client and the message payload as arguments. Any
| values returned from a message handler will be passed to the client's
| acknowledgement callback function if it exists.
| - A catch-all event handler receives the event name as first argument,
| followed by any arguments specific to the event.
| - A catch-all namespace event handler receives the namespace as first
| argument, followed by any arguments specific to the event.
| - A combined catch-all namespace and catch-all event handler receives
| the event name as first argument and the namespace as second
| argument, followed by any arguments specific to the event.
|
| register_namespace(self, namespace_handler)
| Register a namespace handler object.
|
| :param namespace_handler: An instance of a :class:`Namespace`
| subclass that handles all the event traffic
| for a namespace.
|
| rooms(self, sid, namespace=None)
| Return the rooms a client is in.
|
| :param sid: Session ID of the client.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the default namespace is used.
|
| transport(self, sid, namespace=None)
| Return the name of the transport used by the client.
|
| The two possible values returned by this function are ``'polling'``
| and ``'websocket'``.
|
| :param sid: The session of the client.
| :param namespace: The Socket.IO namespace. If this argument is omitted
| the default namespace is used.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketio.base_server.BaseServer:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketio.base_server.BaseServer:
|
| reason = <class 'engineio.base_server.BaseServer.reason'>
| Disconnection reasons.
|
|
| reserved_events = ['connect', 'disconnect']
socketio.AsyncSimpleClient
Python Library Documentation: class AsyncSimpleClient in module socketio.async_simple_client
class AsyncSimpleClient(builtins.object)
| AsyncSimpleClient(*args, **kwargs)
|
| A Socket.IO client.
|
| This class implements a simple, yet fully compliant Socket.IO web client
| with support for websocket and long-polling transports.
|
| The positional and keyword arguments given in the constructor are passed
| to the underlying :func:`socketio.AsyncClient` object.
|
| Methods defined here:
|
| async __aenter__(self)
|
| async __aexit__(self, exc_type, exc_val, exc_tb)
|
| __init__(self, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| async call(self, event, data=None, timeout=60)
| Emit an event to the server and wait for a response.
|
| This method issues an emit and waits for the server to provide a
| response or acknowledgement. If the response does not arrive before the
| timeout, then a ``TimeoutError`` exception is raised.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used.
| :param data: The data to send to the server. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
| :param timeout: The waiting timeout. If the timeout is reached before
| the server acknowledges the event, then a
| ``TimeoutError`` exception is raised.
|
| Note: this method is a coroutine.
|
| async connect(self, url, headers={}, auth=None, transports=None, namespace='/', socketio_path='socket.io', wait_timeout=5)
| Connect to a Socket.IO server.
|
| :param url: The URL of the Socket.IO server. It can include custom
| query string parameters if required by the server. If a
| function is provided, the client will invoke it to obtain
| the URL each time a connection or reconnection is
| attempted.
| :param headers: A dictionary with custom headers to send with the
| connection request. If a function is provided, the
| client will invoke it to obtain the headers dictionary
| each time a connection or reconnection is attempted.
| :param auth: Authentication data passed to the server with the
| connection request, normally a dictionary with one or
| more string key/value pairs. If a function is provided,
| the client will invoke it to obtain the authentication
| data each time a connection or reconnection is attempted.
| :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 namespace: The namespace to connect to as a string. If not
| given, the default namespace ``/`` is used.
| :param socketio_path: The endpoint where the Socket.IO server is
| installed. The default value is appropriate for
| most cases.
| :param wait_timeout: How long the client should wait for the
| connection. The default is 5 seconds.
|
| Note: this method is a coroutine.
|
| async disconnect(self)
| Disconnect from the server.
|
| Note: this method is a coroutine.
|
| async emit(self, event, data=None)
| Emit an event to the server.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used.
| :param data: The data to send to the server. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
|
| Note: this method is a coroutine.
|
| This method schedules the event to be sent out and returns, without
| actually waiting for its delivery. In cases where the client needs to
| ensure that the event was received, :func:`socketio.SimpleClient.call`
| should be used instead.
|
| async receive(self, timeout=None)
| Wait for an event from the server.
|
| :param timeout: The waiting timeout. If the timeout is reached before
| the server acknowledges the event, then a
| ``TimeoutError`` exception is raised.
|
| Note: this method is a coroutine.
|
| The return value is a list with the event name as the first element. If
| the server included arguments with the event, they are returned as
| additional list elements.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| sid
| The session ID received from the server.
|
| The session ID is not guaranteed to remain constant throughout the life
| of the connection, as reconnections can cause it to change.
|
| transport
| The name of the transport currently in use.
|
| The transport is returned as a string and can be one of ``polling``
| and ``websocket``.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| client_class = <class 'socketio.async_client.AsyncClient'>
| A Socket.IO client for asyncio.
|
| This class implements a fully compliant Socket.IO web client with support
| for websocket and long-polling transports.
|
| :param reconnection: ``True`` if the client should automatically attempt to
| reconnect to the server after an interruption, or
| ``False`` to not reconnect. The default is ``True``.
| :param reconnection_attempts: How many reconnection attempts to issue
| before giving up, or 0 for infinite attempts.
| The default is 0.
| :param reconnection_delay: How long to wait in seconds before the first
| reconnection attempt. Each successive attempt
| doubles this delay.
| :param reconnection_delay_max: The maximum delay between reconnection
| attempts.
| :param randomization_factor: Randomization amount for each delay between
| reconnection attempts. The default is 0.5,
| which means that each delay is randomly
| adjusted by +/- 50%.
| :param logger: To enable logging set to ``True`` or pass a logger object to
| use. To disable logging set to ``False``. The default is
| ``False``. Note that fatal errors are logged even when
| ``logger`` is ``False``.
| :param json: An alternative JSON module to use for encoding and decoding
| packets. Custom json modules must have ``dumps`` and ``loads``
| functions that are compatible with the standard library
| versions. This is a process-wide setting, all instantiated
| servers and clients must use the same JSON module.
| :param handle_sigint: Set to ``True`` to automatically handle disconnection
| when the process is interrupted, or to ``False`` to
| leave interrupt handling to the calling application.
| Interrupt handling can only be enabled when the
| client instance is created in the main thread.
|
| The Engine.IO configuration supports the following settings:
|
| :param request_timeout: A timeout in seconds for requests. The default is
| 5 seconds.
| :param http_session: an initialized ``aiohttp.ClientSession`` object to be
| used when sending requests to the server. Use it if
| you need to add special client options such as proxy
| servers, SSL certificates, custom CA bundle, etc.
| :param ssl_verify: ``True`` to verify SSL certificates, or ``False`` to
| skip SSL certificate verification, allowing
| connections to servers with self signed certificates.
| The default is ``True``.
| :param websocket_extra_options: Dictionary containing additional keyword
| arguments passed to
| ``websocket.create_connection()``.
| :param engineio_logger: To enable Engine.IO logging set to ``True`` or pass
| a logger object to use. To disable logging set to
| ``False``. The default is ``False``. Note that
| fatal errors are logged even when
| ``engineio_logger`` is ``False``.
socketio.Client
Python Library Documentation: class Client in module socketio.client
class Client(socketio.base_client.BaseClient)
| Client(reconnection=True, reconnection_attempts=0, reconnection_delay=1, reconnection_delay_max=5, randomization_factor=0.5, logger=False, serializer='default', json=None, handle_sigint=True, **kwargs)
|
| A Socket.IO client.
|
| This class implements a fully compliant Socket.IO web client with support
| for websocket and long-polling transports.
|
| :param reconnection: ``True`` if the client should automatically attempt to
| reconnect to the server after an interruption, or
| ``False`` to not reconnect. The default is ``True``.
| :param reconnection_attempts: How many reconnection attempts to issue
| before giving up, or 0 for infinite attempts.
| The default is 0.
| :param reconnection_delay: How long to wait in seconds before the first
| reconnection attempt. Each successive attempt
| doubles this delay.
| :param reconnection_delay_max: The maximum delay between reconnection
| attempts.
| :param randomization_factor: Randomization amount for each delay between
| reconnection attempts. The default is 0.5,
| which means that each delay is randomly
| adjusted by +/- 50%.
| :param logger: To enable logging set to ``True`` or pass a logger object to
| use. To disable logging set to ``False``. The default is
| ``False``. Note that fatal errors are logged even when
| ``logger`` is ``False``.
| :param serializer: The serialization method to use when transmitting
| packets. Valid values are ``'default'``, ``'pickle'``,
| ``'msgpack'`` and ``'cbor'``. Alternatively, a subclass
| of the :class:`Packet` class with custom implementations
| of the ``encode()`` and ``decode()`` methods can be
| provided. Client and server must use compatible
| serializers.
| :param json: An alternative JSON module to use for encoding and decoding
| packets. Custom json modules must have ``dumps`` and ``loads``
| functions that are compatible with the standard library
| versions. This is a process-wide setting, all instantiated
| servers and clients must use the same JSON module.
| :param handle_sigint: Set to ``True`` to automatically handle disconnection
| when the process is interrupted, or to ``False`` to
| leave interrupt handling to the calling application.
| Interrupt handling can only be enabled when the
| client instance is created in the main thread.
|
| The Engine.IO configuration supports the following settings:
|
| :param request_timeout: A timeout in seconds for requests. The default is
| 5 seconds.
| :param http_session: an initialized ``requests.Session`` object to be used
| when sending requests to the server. Use it if you
| need to add special client options such as proxy
| servers, SSL certificates, custom CA bundle, etc.
| :param ssl_verify: ``True`` to verify SSL certificates, or ``False`` to
| skip SSL certificate verification, allowing
| connections to servers with self signed certificates.
| The default is ``True``.
| :param websocket_extra_options: Dictionary containing additional keyword
| arguments passed to
| ``websocket.create_connection()``.
| :param engineio_logger: To enable Engine.IO logging set to ``True`` or pass
| a logger object to use. To disable logging set to
| ``False``. The default is ``False``. Note that
| fatal errors are logged even when
| ``engineio_logger`` is ``False``.
|
| Method resolution order:
| Client
| socketio.base_client.BaseClient
| builtins.object
|
| Methods defined here:
|
| call(self, event, data=None, namespace=None, timeout=60)
| Emit a custom event to the server and wait for the response.
|
| This method issues an emit with a callback and waits for the callback
| to be invoked before returning. If the callback isn't invoked before
| the timeout, then a ``TimeoutError`` exception is raised. If the
| Socket.IO connection drops during the wait, this method still waits
| until the specified timeout.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used.
| :param data: The data to send to the server. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the event is emitted to the
| default namespace.
| :param timeout: The waiting timeout. If the timeout is reached before
| the server acknowledges the event, then a
| ``TimeoutError`` exception is raised.
|
| Note: this method is not thread safe. If multiple threads are emitting
| at the same time on the same client connection, messages composed of
| multiple packets may end up being sent in an incorrect sequence. Use
| standard concurrency solutions (such as a Lock object) to prevent this
| situation.
|
| connect(self, url, headers={}, auth=None, transports=None, namespaces=None, socketio_path='socket.io', wait=True, wait_timeout=1, retry=False)
| Connect to a Socket.IO server.
|
| :param url: The URL of the Socket.IO server. It can include custom
| query string parameters if required by the server. If a
| function is provided, the client will invoke it to obtain
| the URL each time a connection or reconnection is
| attempted.
| :param headers: A dictionary with custom headers to send with the
| connection request. If a function is provided, the
| client will invoke it to obtain the headers dictionary
| each time a connection or reconnection is attempted.
| :param auth: Authentication data passed to the server with the
| connection request, normally a dictionary with one or
| more string key/value pairs. If a function is provided,
| the client will invoke it to obtain the authentication
| data each time a connection or reconnection is attempted.
| :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.
| :param wait: if set to ``True`` (the default) the call only returns
| when all the namespaces are connected. If set to
| ``False``, the call returns as soon as the Engine.IO
| transport is connected, and the namespaces will connect
| in the background.
| :param wait_timeout: How long the client should wait for the
| connection. The default is 1 second. This
| argument is only considered when ``wait`` is set
| to ``True``.
| :param retry: Apply the reconnection logic if the initial connection
| attempt fails. The default is ``False``.
|
| Example usage::
|
| sio = socketio.Client()
| sio.connect('http://localhost:5000')
|
| disconnect(self)
| Disconnect from the server.
|
| emit(self, event, data=None, namespace=None, callback=None)
| Emit a custom event to the server.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used.
| :param data: The data to send to the server. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the event is emitted to the
| default namespace.
| :param callback: If given, this function will be called to acknowledge
| the server has received the message. The arguments
| that will be passed to the function are those provided
| by the server.
|
| Note: this method is not thread safe. If multiple threads are emitting
| at the same time on the same client connection, messages composed of
| multiple packets may end up being sent in an incorrect sequence. Use
| standard concurrency solutions (such as a Lock object) to prevent this
| situation.
|
| send(self, data, namespace=None, callback=None)
| Send a message to the server.
|
| This function emits an event with the name ``'message'``. Use
| :func:`emit` to issue custom event names.
|
| :param data: The data to send to the server. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the event is emitted to the
| default namespace.
| :param callback: If given, this function will be called to acknowledge
| the server has received the message. The arguments
| that will be passed to the function are those provided
| by the server.
|
| shutdown(self)
| Stop the client.
|
| If the client is connected to a server, it is disconnected. If the
| client is attempting to reconnect to server, the reconnection attempts
| are stopped. If the client is not connected to a server and is not
| attempting to reconnect, then this function does nothing.
|
| sleep(self, seconds=0)
| Sleep for the requested amount of time using the appropriate async
| model.
|
| This is a utility function that applications can use to put a task to
| sleep without having to worry about using the correct call for the
| selected async mode.
|
| start_background_task(self, target, *args, **kwargs)
| Start a background task using the appropriate async model.
|
| This is a utility function that applications can use to start a
| background task using the method that is compatible with the
| selected async mode.
|
| :param target: the target function to execute.
| :param args: arguments to pass to the function.
| :param kwargs: keyword arguments to pass to the function.
|
| This function returns an object that represents the background task,
| on which the ``join()`` methond can be invoked to wait for the task to
| complete.
|
| wait(self)
| Wait until the connection with the server ends.
|
| Client applications can use this function to block the main thread
| during the life of the connection.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.base_client.BaseClient:
|
| __init__(self, reconnection=True, reconnection_attempts=0, reconnection_delay=1, reconnection_delay_max=5, randomization_factor=0.5, logger=False, serializer='default', json=None, handle_sigint=True, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| event(self, *args, **kwargs)
| Decorator to register an event handler.
|
| This is a simplified version of the ``on()`` method that takes the
| event name from the decorated function.
|
| Example usage::
|
| @sio.event
| def my_event(data):
| print('Received data: ', data)
|
| The above example is equivalent to::
|
| @sio.on('my_event')
| def my_event(data):
| print('Received data: ', data)
|
| A custom namespace can be given as an argument to the decorator::
|
| @sio.event(namespace='/test')
| def my_event(data):
| print('Received data: ', data)
|
| get_sid(self, namespace=None)
| Return the ``sid`` associated with a connection.
|
| :param namespace: The Socket.IO namespace. If this argument is omitted
| the handler is associated with the default
| namespace. Note that unlike previous versions, the
| current version of the Socket.IO protocol uses
| different ``sid`` values per namespace.
|
| This method returns the ``sid`` for the requested namespace as a
| string.
|
| is_asyncio_based(self)
|
| on(self, event, handler=None, namespace=None)
| Register an event handler.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used. The ``'*'`` event name
| can be used to define a catch-all event handler.
| :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. A catch-all namespace can be
| defined by passing ``'*'`` as the namespace.
|
| Example usage::
|
| # as a decorator:
| @sio.on('connect')
| def connect_handler():
| print('Connected!')
|
| # as a method:
| def message_handler(msg):
| print('Received message: ', msg)
| sio.send( 'response')
| sio.on('message', message_handler)
|
| The arguments passed to the handler function depend on the event type:
|
| - The ``'connect'`` event handler does not take arguments.
| - The ``'disconnect'`` event handler does not take arguments.
| - The ``'message'`` handler and handlers for custom event names receive
| the message payload as only argument. Any values returned from a
| message handler will be passed to the client's acknowledgement
| callback function if it exists.
| - A catch-all event handler receives the event name as first argument,
| followed by any arguments specific to the event.
| - A catch-all namespace event handler receives the namespace as first
| argument, followed by any arguments specific to the event.
| - A combined catch-all namespace and catch-all event handler receives
| the event name as first argument and the namespace as second
| argument, followed by any arguments specific to the event.
|
| register_namespace(self, namespace_handler)
| Register a namespace handler object.
|
| :param namespace_handler: An instance of a :class:`Namespace`
| subclass that handles all the event traffic
| for a namespace.
|
| transport(self)
| Return the name of the transport used by the client.
|
| The two possible values returned by this function are ``'polling'``
| and ``'websocket'``.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketio.base_client.BaseClient:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketio.base_client.BaseClient:
|
| reason = <class 'engineio.base_client.BaseClient.reason'>
| Disconnection reasons.
|
|
| reserved_events = ['connect', 'connect_error', 'disconnect', '__discon...
socketio.ClientNamespace
Python Library Documentation: class ClientNamespace in module socketio.namespace class ClientNamespace(socketio.base_namespace.BaseClientNamespace) | ClientNamespace(namespace=None) | | Base class for client-side class-based namespaces. | | A class-based namespace is a class that contains all the event handlers | for a Socket.IO namespace. The event handlers are methods of the class | with the prefix ``on_``, such as ``on_connect``, ``on_disconnect``, | ``on_message``, ``on_json``, and so on. | | :param namespace: The Socket.IO namespace to be used with all the event | handlers defined in this class. If this argument is | omitted, the default namespace is used. | | Method resolution order: | ClientNamespace | socketio.base_namespace.BaseClientNamespace | socketio.base_namespace.BaseNamespace | builtins.object | | Methods defined here: | | call(self, event, data=None, namespace=None, timeout=None) | Emit a custom event to the server and wait for the response. | | The only difference with the :func:`socketio.Client.call` method is | that when the ``namespace`` argument is not given the namespace | associated with the class is used. | | disconnect(self) | Disconnect from the server. | | The only difference with the :func:`socketio.Client.disconnect` method | is that when the ``namespace`` argument is not given the namespace | associated with the class is used. | | emit(self, event, data=None, namespace=None, callback=None) | Emit a custom event to the server. | | The only difference with the :func:`socketio.Client.emit` method is | that when the ``namespace`` argument is not given the namespace | associated with the class is used. | | send(self, data, room=None, namespace=None, callback=None) | Send a message to the server. | | The only difference with the :func:`socketio.Client.send` method is | that when the ``namespace`` argument is not given the namespace | associated with the class is used. | | trigger_event(self, event, *args) | Dispatch an event to the proper handler method. | | In the most common usage, this method is not overloaded by subclasses, | as it performs the routing of events to methods. However, this | method can be overridden if special dispatching rules are needed, or if | having a single method that catches all events is desired. | | ---------------------------------------------------------------------- | Methods inherited from socketio.base_namespace.BaseClientNamespace: | | __init__(self, namespace=None) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from socketio.base_namespace.BaseNamespace: | | is_asyncio_based(self) | | ---------------------------------------------------------------------- | Data descriptors inherited from socketio.base_namespace.BaseNamespace: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
socketio.KafkaManager
Python Library Documentation: class KafkaManager in module socketio.kafka_manager class KafkaManager(socketio.pubsub_manager.PubSubManager) | KafkaManager(url='kafka://localhost:9092', channel='socketio', write_only=False, logger=None, json=None) | | Kafka based client manager. | | This class implements a Kafka backend for event sharing across multiple | processes. | | To use a Kafka backend, initialize the :class:`Server` instance as | follows:: | | url = 'kafka://hostname:port' | server = socketio.Server(client_manager=socketio.KafkaManager(url)) | | :param url: The connection URL for the Kafka server. For a default Kafka | store running on the same host, use ``kafka://``. For a highly | available deployment of Kafka, pass a list with all the | connection URLs available in your cluster. | :param channel: The channel name (topic) on which the server sends and | receives notifications. Must be the same in all the | servers. | :param write_only: If set to ``True``, only initialize to emit events. The | default of ``False`` initializes the class for emitting | and receiving. A write-only instance can be used | independently of the server to emit to clients from an | external process. | :param logger: a custom logger to log it. If not given, the server logger | is used. | :param json: An alternative JSON module to use for encoding and decoding | packets. Custom json modules must have ``dumps`` and ``loads`` | functions that are compatible with the standard library | versions. This setting is only used when ``write_only`` is set | to ``True``. Otherwise the JSON module configured in the | server is used. | | Method resolution order: | KafkaManager | socketio.pubsub_manager.PubSubManager | socketio.manager.Manager | socketio.base_manager.BaseManager | builtins.object | | Methods defined here: | | __init__(self, url='kafka://localhost:9092', channel='socketio', write_only=False, logger=None, json=None) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | name = 'kafka' | | ---------------------------------------------------------------------- | Methods inherited from socketio.pubsub_manager.PubSubManager: | | can_disconnect(self, sid, namespace) | | close_room(self, room, namespace=None) | Remove all participants from a room. | | disconnect(self, sid, namespace=None, **kwargs) | Register a client disconnect from a namespace. | | emit(self, event, data, namespace=None, room=None, skip_sid=None, callback=None, to=None, **kwargs) | Emit a message to a single client, a room, or all the clients | connected to the namespace. | | This method takes care or propagating the message to all the servers | that are connected through the message queue. | | The parameters are the same as in :meth:`.Server.emit`. | | enter_room(self, sid, namespace, room, eio_sid=None) | Add a client to a room. | | initialize(self) | Invoked before the first request is received. Subclasses can add | their initialization code here. | | leave_room(self, sid, namespace, room) | Remove a client from a room. | | ---------------------------------------------------------------------- | Methods inherited from socketio.manager.Manager: | | trigger_callback(self, sid, id, data) | Invoke an application callback. | | ---------------------------------------------------------------------- | Methods inherited from socketio.base_manager.BaseManager: | | basic_close_room(self, room, namespace) | | basic_disconnect(self, sid, namespace, **kwargs) | | basic_enter_room(self, sid, namespace, room, eio_sid=None) | | basic_leave_room(self, sid, namespace, room) | | connect(self, eio_sid, namespace) | Register a client connection to a namespace. | | eio_sid_from_sid(self, sid, namespace) | | get_namespaces(self) | Return an iterable with the active namespace names. | | get_participants(self, namespace, room) | Return an iterable with the active participants in a room. | | Note that in a multi-server scenario this method only returns the | participants connect to the server in which the method is called. There | is currently no functionality to assemble a complete list of users | across multiple servers. | | get_rooms(self, sid, namespace) | Return the rooms a client is in. | | is_connected(self, sid, namespace) | | pre_disconnect(self, sid, namespace) | Put the client in the to-be-disconnected list. | | This allows the client data structures to be present while the | disconnect handler is invoked, but still recognize the fact that the | client is soon going away. | | set_server(self, server) | | sid_from_eio_sid(self, eio_sid, namespace) | | ---------------------------------------------------------------------- | Data descriptors inherited from socketio.base_manager.BaseManager: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
socketio.KombuManager
Python Library Documentation: class KombuManager in module socketio.kombu_manager class KombuManager(socketio.pubsub_manager.PubSubManager) | KombuManager(url='amqp://guest:guest@localhost:5672//', channel='socketio', write_only=False, logger=None, json=None, connection_options=None, exchange_options=None, queue_options=None, producer_options=None) | | Client manager that uses kombu for inter-process messaging. | | This class implements a client manager backend for event sharing across | multiple processes, using RabbitMQ, Redis or any other messaging mechanism | supported by `kombu <http://kombu.readthedocs.org/en/latest/>`_. | | To use a kombu backend, initialize the :class:`Server` instance as | follows:: | | url = 'amqp://user:password@hostname:port//' | server = socketio.Server(client_manager=socketio.KombuManager(url)) | | :param url: The connection URL for the backend messaging queue. Example | connection URLs are ``'amqp://guest:guest@localhost:5672//'`` | and ``'redis://localhost:6379/'`` for RabbitMQ and Redis | respectively. Consult the `kombu documentation | <http://kombu.readthedocs.org/en/latest/userguide /connections.html#urls>`_ for more on how to construct | connection URLs. | :param channel: The channel name on which the server sends and receives | notifications. Must be the same in all the servers. | :param write_only: If set to ``True``, only initialize to emit events. The | default of ``False`` initializes the class for emitting | and receiving. A write-only instance can be used | independently of the server to emit to clients from an | external process. | :param logger: a custom logger to log it. If not given, the server logger | is used. | :param json: An alternative JSON module to use for encoding and decoding | packets. Custom json modules must have ``dumps`` and ``loads`` | functions that are compatible with the standard library | versions. This setting is only used when ``write_only`` is set | to ``True``. Otherwise the JSON module configured in the | server is used. | :param connection_options: additional keyword arguments to be passed to | ``kombu.Connection()``. | :param exchange_options: additional keyword arguments to be passed to | ``kombu.Exchange()``. | :param queue_options: additional keyword arguments to be passed to | ``kombu.Queue()``. | :param producer_options: additional keyword arguments to be passed to | ``kombu.Producer()``. | | Method resolution order: | KombuManager | socketio.pubsub_manager.PubSubManager | socketio.manager.Manager | socketio.base_manager.BaseManager | builtins.object | | Methods defined here: | | __init__(self, url='amqp://guest:guest@localhost:5672//', channel='socketio', write_only=False, logger=None, json=None, connection_options=None, exchange_options=None, queue_options=None, producer_options=None) | Initialize self. See help(type(self)) for accurate signature. | | initialize(self) | Invoked before the first request is received. Subclasses can add | their initialization code here. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | name = 'kombu' | | ---------------------------------------------------------------------- | Methods inherited from socketio.pubsub_manager.PubSubManager: | | can_disconnect(self, sid, namespace) | | close_room(self, room, namespace=None) | Remove all participants from a room. | | disconnect(self, sid, namespace=None, **kwargs) | Register a client disconnect from a namespace. | | emit(self, event, data, namespace=None, room=None, skip_sid=None, callback=None, to=None, **kwargs) | Emit a message to a single client, a room, or all the clients | connected to the namespace. | | This method takes care or propagating the message to all the servers | that are connected through the message queue. | | The parameters are the same as in :meth:`.Server.emit`. | | enter_room(self, sid, namespace, room, eio_sid=None) | Add a client to a room. | | leave_room(self, sid, namespace, room) | Remove a client from a room. | | ---------------------------------------------------------------------- | Methods inherited from socketio.manager.Manager: | | trigger_callback(self, sid, id, data) | Invoke an application callback. | | ---------------------------------------------------------------------- | Methods inherited from socketio.base_manager.BaseManager: | | basic_close_room(self, room, namespace) | | basic_disconnect(self, sid, namespace, **kwargs) | | basic_enter_room(self, sid, namespace, room, eio_sid=None) | | basic_leave_room(self, sid, namespace, room) | | connect(self, eio_sid, namespace) | Register a client connection to a namespace. | | eio_sid_from_sid(self, sid, namespace) | | get_namespaces(self) | Return an iterable with the active namespace names. | | get_participants(self, namespace, room) | Return an iterable with the active participants in a room. | | Note that in a multi-server scenario this method only returns the | participants connect to the server in which the method is called. There | is currently no functionality to assemble a complete list of users | across multiple servers. | | get_rooms(self, sid, namespace) | Return the rooms a client is in. | | is_connected(self, sid, namespace) | | pre_disconnect(self, sid, namespace) | Put the client in the to-be-disconnected list. | | This allows the client data structures to be present while the | disconnect handler is invoked, but still recognize the fact that the | client is soon going away. | | set_server(self, server) | | sid_from_eio_sid(self, eio_sid, namespace) | | ---------------------------------------------------------------------- | Data descriptors inherited from socketio.base_manager.BaseManager: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
socketio.Manager
Python Library Documentation: class Manager in module socketio.manager class Manager(socketio.base_manager.BaseManager) | Manage client connections. | | This class keeps track of all the clients and the rooms they are in, to | support the broadcasting of messages. The data used by this class is | stored in a memory structure, making it appropriate only for single process | services. More sophisticated storage backends can be implemented by | subclasses. | | Method resolution order: | Manager | socketio.base_manager.BaseManager | builtins.object | | Methods defined here: | | can_disconnect(self, sid, namespace) | | close_room(self, room, namespace) | Remove all participants from a room. | | disconnect(self, sid, namespace, **kwargs) | Register a client disconnect from a namespace. | | emit(self, event, data, namespace, room=None, skip_sid=None, callback=None, to=None, **kwargs) | Emit a message to a single client, a room, or all the clients | connected to the namespace. | | enter_room(self, sid, namespace, room, eio_sid=None) | Add a client to a room. | | leave_room(self, sid, namespace, room) | Remove a client from a room. | | trigger_callback(self, sid, id, data) | Invoke an application callback. | | ---------------------------------------------------------------------- | Methods inherited from socketio.base_manager.BaseManager: | | __init__(self) | Initialize self. See help(type(self)) for accurate signature. | | basic_close_room(self, room, namespace) | | basic_disconnect(self, sid, namespace, **kwargs) | | basic_enter_room(self, sid, namespace, room, eio_sid=None) | | basic_leave_room(self, sid, namespace, room) | | connect(self, eio_sid, namespace) | Register a client connection to a namespace. | | eio_sid_from_sid(self, sid, namespace) | | get_namespaces(self) | Return an iterable with the active namespace names. | | get_participants(self, namespace, room) | Return an iterable with the active participants in a room. | | Note that in a multi-server scenario this method only returns the | participants connect to the server in which the method is called. There | is currently no functionality to assemble a complete list of users | across multiple servers. | | get_rooms(self, sid, namespace) | Return the rooms a client is in. | | initialize(self) | Invoked before the first request is received. Subclasses can add | their initialization code here. | | is_connected(self, sid, namespace) | | pre_disconnect(self, sid, namespace) | Put the client in the to-be-disconnected list. | | This allows the client data structures to be present while the | disconnect handler is invoked, but still recognize the fact that the | client is soon going away. | | set_server(self, server) | | sid_from_eio_sid(self, eio_sid, namespace) | | ---------------------------------------------------------------------- | Data descriptors inherited from socketio.base_manager.BaseManager: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
socketio.Middleware
Python Library Documentation: class Middleware in module socketio.middleware class Middleware(WSGIApp) | Middleware(socketio_app, wsgi_app=None, socketio_path='socket.io') | | This class has been renamed to WSGIApp and is now deprecated. | | Method resolution order: | Middleware | WSGIApp | engineio.middleware.WSGIApp | builtins.object | | Methods defined here: | | __init__(self, socketio_app, wsgi_app=None, socketio_path='socket.io') | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from engineio.middleware.WSGIApp: | | __call__(self, environ, start_response) | Call self as a function. | | not_found(self, start_response) | | ---------------------------------------------------------------------- | Data descriptors inherited from engineio.middleware.WSGIApp: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
socketio.Namespace
Python Library Documentation: class Namespace in module socketio.namespace class Namespace(socketio.base_namespace.BaseServerNamespace) | Namespace(namespace=None) | | Base class for server-side class-based namespaces. | | A class-based namespace is a class that contains all the event handlers | for a Socket.IO namespace. The event handlers are methods of the class | with the prefix ``on_``, such as ``on_connect``, ``on_disconnect``, | ``on_message``, ``on_json``, and so on. | | :param namespace: The Socket.IO namespace to be used with all the event | handlers defined in this class. If this argument is | omitted, the default namespace is used. | | Method resolution order: | Namespace | socketio.base_namespace.BaseServerNamespace | socketio.base_namespace.BaseNamespace | builtins.object | | Methods defined here: | | call(self, event, data=None, to=None, sid=None, namespace=None, timeout=None, ignore_queue=False) | Emit a custom event to a client and wait for the response. | | The only difference with the :func:`socketio.Server.call` method is | that when the ``namespace`` argument is not given the namespace | associated with the class is used. | | close_room(self, room, namespace=None) | Close a room. | | The only difference with the :func:`socketio.Server.close_room` method | is that when the ``namespace`` argument is not given the namespace | associated with the class is used. | | disconnect(self, sid, namespace=None) | Disconnect a client. | | The only difference with the :func:`socketio.Server.disconnect` method | is that when the ``namespace`` argument is not given the namespace | associated with the class is used. | | emit(self, event, data=None, to=None, room=None, skip_sid=None, namespace=None, callback=None, ignore_queue=False) | Emit a custom event to one or more connected clients. | | The only difference with the :func:`socketio.Server.emit` method is | that when the ``namespace`` argument is not given the namespace | associated with the class is used. | | enter_room(self, sid, room, namespace=None) | Enter a room. | | The only difference with the :func:`socketio.Server.enter_room` method | is that when the ``namespace`` argument is not given the namespace | associated with the class is used. | | get_session(self, sid, namespace=None) | Return the user session for a client. | | The only difference with the :func:`socketio.Server.get_session` | method is that when the ``namespace`` argument is not given the | namespace associated with the class is used. | | leave_room(self, sid, room, namespace=None) | Leave a room. | | The only difference with the :func:`socketio.Server.leave_room` method | is that when the ``namespace`` argument is not given the namespace | associated with the class is used. | | save_session(self, sid, session, namespace=None) | Store the user session for a client. | | The only difference with the :func:`socketio.Server.save_session` | method is that when the ``namespace`` argument is not given the | namespace associated with the class is used. | | send(self, data, to=None, room=None, skip_sid=None, namespace=None, callback=None, ignore_queue=False) | Send a message to one or more connected clients. | | The only difference with the :func:`socketio.Server.send` method is | that when the ``namespace`` argument is not given the namespace | associated with the class is used. | | session(self, sid, namespace=None) | Return the user session for a client with context manager syntax. | | The only difference with the :func:`socketio.Server.session` method is | that when the ``namespace`` argument is not given the namespace | associated with the class is used. | | trigger_event(self, event, *args) | Dispatch an event to the proper handler method. | | In the most common usage, this method is not overloaded by subclasses, | as it performs the routing of events to methods. However, this | method can be overridden if special dispatching rules are needed, or if | having a single method that catches all events is desired. | | ---------------------------------------------------------------------- | Methods inherited from socketio.base_namespace.BaseServerNamespace: | | __init__(self, namespace=None) | Initialize self. See help(type(self)) for accurate signature. | | rooms(self, sid, namespace=None) | Return the rooms a client is in. | | The only difference with the :func:`socketio.Server.rooms` method is | that when the ``namespace`` argument is not given the namespace | associated with the class is used. | | ---------------------------------------------------------------------- | Methods inherited from socketio.base_namespace.BaseNamespace: | | is_asyncio_based(self) | | ---------------------------------------------------------------------- | Data descriptors inherited from socketio.base_namespace.BaseNamespace: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
socketio.PubSubManager
Python Library Documentation: class PubSubManager in module socketio.pubsub_manager class PubSubManager(socketio.manager.Manager) | PubSubManager(channel='socketio', write_only=False, logger=None, json=None) | | Manage a client list attached to a pub/sub backend. | | This is a base class that enables multiple servers to share the list of | clients, with the servers communicating events through a pub/sub backend. | The use of a pub/sub backend also allows any client connected to the | backend to emit events addressed to Socket.IO clients. | | The actual backends must be implemented by subclasses, this class only | provides a pub/sub generic framework. | | :param channel: The channel name on which the server sends and receives | notifications. | :param write_only: If set to ``True``, only initialize to emit events. The | default of ``False`` initializes the class for emitting | and receiving. A write-only instance can be used | independently of the server to emit to clients from an | external process. | :param logger: a custom logger to log it. If not given, the server logger | is used. | :param json: An alternative JSON module to use for encoding and decoding | packets. Custom json modules must have ``dumps`` and ``loads`` | functions that are compatible with the standard library | versions. This setting is only used when ``write_only`` is set | to ``True``. Otherwise the JSON module configured in the | server is used. | | Method resolution order: | PubSubManager | socketio.manager.Manager | socketio.base_manager.BaseManager | builtins.object | | Methods defined here: | | __init__(self, channel='socketio', write_only=False, logger=None, json=None) | Initialize self. See help(type(self)) for accurate signature. | | can_disconnect(self, sid, namespace) | | close_room(self, room, namespace=None) | Remove all participants from a room. | | disconnect(self, sid, namespace=None, **kwargs) | Register a client disconnect from a namespace. | | emit(self, event, data, namespace=None, room=None, skip_sid=None, callback=None, to=None, **kwargs) | Emit a message to a single client, a room, or all the clients | connected to the namespace. | | This method takes care or propagating the message to all the servers | that are connected through the message queue. | | The parameters are the same as in :meth:`.Server.emit`. | | enter_room(self, sid, namespace, room, eio_sid=None) | Add a client to a room. | | initialize(self) | Invoked before the first request is received. Subclasses can add | their initialization code here. | | leave_room(self, sid, namespace, room) | Remove a client from a room. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | name = 'pubsub' | | ---------------------------------------------------------------------- | Methods inherited from socketio.manager.Manager: | | trigger_callback(self, sid, id, data) | Invoke an application callback. | | ---------------------------------------------------------------------- | Methods inherited from socketio.base_manager.BaseManager: | | basic_close_room(self, room, namespace) | | basic_disconnect(self, sid, namespace, **kwargs) | | basic_enter_room(self, sid, namespace, room, eio_sid=None) | | basic_leave_room(self, sid, namespace, room) | | connect(self, eio_sid, namespace) | Register a client connection to a namespace. | | eio_sid_from_sid(self, sid, namespace) | | get_namespaces(self) | Return an iterable with the active namespace names. | | get_participants(self, namespace, room) | Return an iterable with the active participants in a room. | | Note that in a multi-server scenario this method only returns the | participants connect to the server in which the method is called. There | is currently no functionality to assemble a complete list of users | across multiple servers. | | get_rooms(self, sid, namespace) | Return the rooms a client is in. | | is_connected(self, sid, namespace) | | pre_disconnect(self, sid, namespace) | Put the client in the to-be-disconnected list. | | This allows the client data structures to be present while the | disconnect handler is invoked, but still recognize the fact that the | client is soon going away. | | set_server(self, server) | | sid_from_eio_sid(self, eio_sid, namespace) | | ---------------------------------------------------------------------- | Data descriptors inherited from socketio.base_manager.BaseManager: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
socketio.RedisManager
Python Library Documentation: class RedisManager in module socketio.redis_manager class RedisManager(socketio.pubsub_manager.PubSubManager) | RedisManager(url='redis://localhost:6379/0', channel='socketio', write_only=False, logger=None, json=None, redis_options=None) | | Redis based client manager. | | This class implements a Redis backend for event sharing across multiple | processes. Only kept here as one more example of how to build a custom | backend, since the kombu backend is perfectly adequate to support a Redis | message queue. | | To use a Redis backend, initialize the :class:`Server` instance as | follows:: | | url = 'redis://hostname:port/0' | server = socketio.Server(client_manager=socketio.RedisManager(url)) | | :param url: The connection URL for the Redis server. For a default Redis | store running on the same host, use ``redis://``. To use a | TLS connection, use ``rediss://``. To use Redis Sentinel, use | ``redis+sentinel://`` with a comma-separated list of hosts | and the service name after the db in the URL path. Example: | ``redis+sentinel://user:pw@host1:1234,host2:2345/0/myredis``. | :param channel: The channel name on which the server sends and receives | notifications. Must be the same in all the servers. | :param write_only: If set to ``True``, only initialize to emit events. The | default of ``False`` initializes the class for emitting | and receiving. A write-only instance can be used | independently of the server to emit to clients from an | external process. | :param logger: a custom logger to log it. If not given, the server logger | is used. | :param json: An alternative JSON module to use for encoding and decoding | packets. Custom json modules must have ``dumps`` and ``loads`` | functions that are compatible with the standard library | versions. This setting is only used when ``write_only`` is set | to ``True``. Otherwise the JSON module configured in the | server is used. | :param redis_options: additional keyword arguments to be passed to | ``Redis.from_url()`` or ``Sentinel()``. | | Method resolution order: | RedisManager | socketio.pubsub_manager.PubSubManager | socketio.manager.Manager | socketio.base_manager.BaseManager | builtins.object | | Methods defined here: | | __init__(self, url='redis://localhost:6379/0', channel='socketio', write_only=False, logger=None, json=None, redis_options=None) | Initialize self. See help(type(self)) for accurate signature. | | initialize(self) | Invoked before the first request is received. Subclasses can add | their initialization code here. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | name = 'redis' | | ---------------------------------------------------------------------- | Methods inherited from socketio.pubsub_manager.PubSubManager: | | can_disconnect(self, sid, namespace) | | close_room(self, room, namespace=None) | Remove all participants from a room. | | disconnect(self, sid, namespace=None, **kwargs) | Register a client disconnect from a namespace. | | emit(self, event, data, namespace=None, room=None, skip_sid=None, callback=None, to=None, **kwargs) | Emit a message to a single client, a room, or all the clients | connected to the namespace. | | This method takes care or propagating the message to all the servers | that are connected through the message queue. | | The parameters are the same as in :meth:`.Server.emit`. | | enter_room(self, sid, namespace, room, eio_sid=None) | Add a client to a room. | | leave_room(self, sid, namespace, room) | Remove a client from a room. | | ---------------------------------------------------------------------- | Methods inherited from socketio.manager.Manager: | | trigger_callback(self, sid, id, data) | Invoke an application callback. | | ---------------------------------------------------------------------- | Methods inherited from socketio.base_manager.BaseManager: | | basic_close_room(self, room, namespace) | | basic_disconnect(self, sid, namespace, **kwargs) | | basic_enter_room(self, sid, namespace, room, eio_sid=None) | | basic_leave_room(self, sid, namespace, room) | | connect(self, eio_sid, namespace) | Register a client connection to a namespace. | | eio_sid_from_sid(self, sid, namespace) | | get_namespaces(self) | Return an iterable with the active namespace names. | | get_participants(self, namespace, room) | Return an iterable with the active participants in a room. | | Note that in a multi-server scenario this method only returns the | participants connect to the server in which the method is called. There | is currently no functionality to assemble a complete list of users | across multiple servers. | | get_rooms(self, sid, namespace) | Return the rooms a client is in. | | is_connected(self, sid, namespace) | | pre_disconnect(self, sid, namespace) | Put the client in the to-be-disconnected list. | | This allows the client data structures to be present while the | disconnect handler is invoked, but still recognize the fact that the | client is soon going away. | | set_server(self, server) | | sid_from_eio_sid(self, eio_sid, namespace) | | ---------------------------------------------------------------------- | Data descriptors inherited from socketio.base_manager.BaseManager: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
socketio.Server
Python Library Documentation: class Server in module socketio.server
class Server(socketio.base_server.BaseServer)
| Server(client_manager=None, logger=False, serializer='default', json=None, async_handlers=True, always_connect=False, namespaces=None, **kwargs)
|
| A Socket.IO server.
|
| This class implements a fully compliant Socket.IO web server with support
| for websocket and long-polling transports.
|
| :param client_manager: The client manager instance that will manage the
| client list. When this is omitted, the client list
| is stored in an in-memory structure, so the use of
| multiple connected servers is not possible.
| :param logger: To enable logging set to ``True`` or pass a logger object to
| use. To disable logging set to ``False``. The default is
| ``False``. Note that fatal errors are logged even when
| ``logger`` is ``False``.
| :param serializer: The serialization method to use when transmitting
| packets. Valid values are ``'default'``, ``'pickle'``,
| ``'msgpack'`` and ``'cbor'``. Alternatively, a subclass
| of the :class:`Packet` class with custom implementations
| of the ``encode()`` and ``decode()`` methods can be
| provided. Client and server must use compatible
| serializers.
| :param json: An alternative JSON module to use for encoding and decoding
| packets. Custom json modules must have ``dumps`` and ``loads``
| functions that are compatible with the standard library
| versions. This is a process-wide setting, all instantiated
| servers and clients must use the same JSON module.
| :param async_handlers: If set to ``True``, event handlers for a client are
| executed in separate threads. To run handlers for a
| client synchronously, set to ``False``. The default
| is ``True``.
| :param always_connect: When set to ``False``, new connections are
| provisory until the connect handler returns
| something other than ``False``, at which point they
| are accepted. When set to ``True``, connections are
| immediately accepted, and then if the connect
| handler returns ``False`` a disconnect is issued.
| Set to ``True`` if you need to emit events from the
| connect handler and your client is confused when it
| receives events before the connection acceptance.
| In any other case use the default of ``False``.
| :param namespaces: a list of namespaces that are accepted, in addition to
| any namespaces for which handlers have been defined. The
| default is `['/']`, which always accepts connections to
| the default namespace. Set to `'*'` to accept all
| namespaces.
| :param kwargs: Connection parameters for the underlying Engine.IO server.
|
| The Engine.IO configuration supports the following settings:
|
| :param async_mode: The asynchronous model to use. See the Deployment
| section in the documentation for a description of the
| available options. Valid async modes are
| ``'threading'``, ``'eventlet'``, ``'gevent'`` and
| ``'gevent_uwsgi'``. If this argument is not given,
| ``'eventlet'`` is tried first, then ``'gevent_uwsgi'``,
| then ``'gevent'``, and finally ``'threading'``.
| The first async mode that has all its dependencies
| installed is then one that is chosen.
| :param ping_interval: The interval in seconds at which the server pings
| the client. The default is 25 seconds. For advanced
| control, a two element tuple can be given, where
| the first number is the ping interval and the second
| is a grace period added by the server.
| :param ping_timeout: The time in seconds that the client waits for the
| server to respond before disconnecting. The default
| is 20 seconds.
| :param max_http_buffer_size: The maximum size that is accepted for incoming
| messages. The default is 1,000,000 bytes. In
| spite of its name, the value set in this
| argument is enforced for HTTP long-polling and
| WebSocket connections.
| :param allow_upgrades: Whether to allow transport upgrades or not. The
| default is ``True``.
| :param http_compression: Whether to compress packages when using the
| polling transport. The default is ``True``.
| :param compression_threshold: Only compress messages when their byte size
| is greater than this value. The default is
| 1024 bytes.
| :param cookie: If set to a string, it is the name of the HTTP cookie the
| server sends back to the client containing the client
| session id. If set to a dictionary, the ``'name'`` key
| contains the cookie name and other keys define cookie
| attributes, where the value of each attribute can be a
| string, a callable with no arguments, or a boolean. If set
| to ``None`` (the default), a cookie is not sent to the
| client.
| :param cors_allowed_origins: Origin or list of origins that are allowed to
| connect to this server. Only the same origin
| is allowed by default. Set this argument to
| ``'*'`` to allow all origins, or to ``[]`` to
| disable CORS handling.
| :param cors_credentials: Whether credentials (cookies, authentication) are
| allowed in requests to this server. The default is
| ``True``.
| :param monitor_clients: If set to ``True``, a background task will ensure
| inactive clients are closed. Set to ``False`` to
| disable the monitoring task (not recommended). The
| default is ``True``.
| :param transports: The list of allowed transports. Valid transports
| are ``'polling'`` and ``'websocket'``. Defaults to
| ``['polling', 'websocket']``.
| :param engineio_logger: To enable Engine.IO logging set to ``True`` or pass
| a logger object to use. To disable logging set to
| ``False``. The default is ``False``. Note that
| fatal errors are logged even when
| ``engineio_logger`` is ``False``.
|
| Method resolution order:
| Server
| socketio.base_server.BaseServer
| builtins.object
|
| Methods defined here:
|
| call(self, event, data=None, to=None, sid=None, namespace=None, timeout=60, ignore_queue=False)
| Emit a custom event to a client and wait for the response.
|
| This method issues an emit with a callback and waits for the callback
| to be invoked before returning. If the callback isn't invoked before
| the timeout, then a ``TimeoutError`` exception is raised. If the
| Socket.IO connection drops during the wait, this method still waits
| until the specified timeout.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used.
| :param data: The data to send to the client or clients. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
| :param to: The session ID of the recipient client.
| :param sid: Alias for the ``to`` parameter.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the event is emitted to the
| default namespace.
| :param timeout: The waiting timeout. If the timeout is reached before
| the client acknowledges the event, then a
| ``TimeoutError`` exception is raised.
| :param ignore_queue: Only used when a message queue is configured. If
| set to ``True``, the event is emitted to the
| client directly, without going through the queue.
| This is more efficient, but only works when a
| single server process is used. It is recommended
| to always leave this parameter with its default
| value of ``False``.
|
| Note: this method is not thread safe. If multiple threads are emitting
| at the same time to the same client, then messages composed of
| multiple packets may end up being sent in an incorrect sequence. Use
| standard concurrency solutions (such as a Lock object) to prevent this
| situation.
|
| close_room(self, room, namespace=None)
| Close a room.
|
| This function removes all the clients from the given room.
|
| :param room: Room name.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the default namespace is used.
|
| disconnect(self, sid, namespace=None, ignore_queue=False)
| Disconnect a client.
|
| :param sid: Session ID of the client.
| :param namespace: The Socket.IO namespace to disconnect. If this
| argument is omitted the default namespace is used.
| :param ignore_queue: Only used when a message queue is configured. If
| set to ``True``, the disconnect is processed
| locally, without broadcasting on the queue. It is
| recommended to always leave this parameter with
| its default value of ``False``.
|
| emit(self, event, data=None, to=None, room=None, skip_sid=None, namespace=None, callback=None, ignore_queue=False)
| Emit a custom event to one or more connected clients.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used.
| :param data: The data to send to the client or clients. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
| :param to: The recipient of the message. This can be set to the
| session ID of a client to address only that client, to any
| custom room created by the application to address all
| the clients in that room, or to a list of custom room
| names. If this argument is omitted the event is broadcasted
| to all connected clients.
| :param room: Alias for the ``to`` parameter.
| :param skip_sid: The session ID of a client to skip when broadcasting
| to a room or to all clients. This can be used to
| prevent a message from being sent to the sender. To
| skip multiple sids, pass a list.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the event is emitted to the
| default namespace.
| :param callback: If given, this function will be called to acknowledge
| the client has received the message. The arguments
| that will be passed to the function are those provided
| by the client. Callback functions can only be used
| when addressing an individual client.
| :param ignore_queue: Only used when a message queue is configured. If
| set to ``True``, the event is emitted to the
| clients directly, without going through the queue.
| This is more efficient, but only works when a
| single server process is used. It is recommended
| to always leave this parameter with its default
| value of ``False``.
|
| Note: this method is not thread safe. If multiple threads are emitting
| at the same time to the same client, then messages composed of
| multiple packets may end up being sent in an incorrect sequence. Use
| standard concurrency solutions (such as a Lock object) to prevent this
| situation.
|
| enter_room(self, sid, room, namespace=None)
| Enter a room.
|
| This function adds the client to a room. The :func:`emit` and
| :func:`send` functions can optionally broadcast events to all the
| clients in a room.
|
| :param sid: Session ID of the client.
| :param room: Room name. If the room does not exist it is created.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the default namespace is used.
|
| get_session(self, sid, namespace=None)
| Return the user session for a client.
|
| :param sid: The session id of the client.
| :param namespace: The Socket.IO namespace. If this argument is omitted
| the default namespace is used.
|
| The return value is a dictionary. Modifications made to this
| dictionary are not guaranteed to be preserved unless
| ``save_session()`` is called, or when the ``session`` context manager
| is used.
|
| handle_request(self, environ, start_response)
| Handle an HTTP request from the client.
|
| This is the entry point of the Socket.IO application, using the same
| interface as a WSGI application. For the typical usage, this function
| is invoked by the :class:`Middleware` instance, but it can be invoked
| directly when the middleware is not used.
|
| :param environ: The WSGI environment.
| :param start_response: The WSGI ``start_response`` function.
|
| This function returns the HTTP response body to deliver to the client
| as a byte sequence.
|
| instrument(self, auth=None, mode='development', read_only=False, server_id=None, namespace='/admin', server_stats_interval=2)
| Instrument the Socket.IO server for monitoring with the `Socket.IO
| Admin UI <https://socket.io/docs/v4/admin-ui/>`_.
|
| :param auth: Authentication credentials for Admin UI access. Set to a
| dictionary with the expected login (usually ``username``
| and ``password``) or a list of dictionaries if more than
| one set of credentials need to be available. For more
| complex authentication methods, set to a callable that
| receives the authentication dictionary as an argument and
| returns ``True`` if the user is allowed or ``False``
| otherwise. To disable authentication, set this argument to
| ``False`` (not recommended, never do this on a production
| server).
| :param mode: The reporting mode. The default is ``'development'``,
| which is best used while debugging, as it may have a
| significant performance effect. Set to ``'production'`` to
| reduce the amount of information that is reported to the
| admin UI.
| :param read_only: If set to ``True``, the admin interface will be
| read-only, with no option to modify room assignments
| or disconnect clients. The default is ``False``.
| :param server_id: The server name to use for this server. If this
| argument is omitted, the server generates its own
| name.
| :param namespace: The Socket.IO namespace to use for the admin
| interface. The default is ``/admin``.
| :param server_stats_interval: The interval in seconds at which the
| server emits a summary of it stats to all
| connected admins.
|
| leave_room(self, sid, room, namespace=None)
| Leave a room.
|
| This function removes the client from a room.
|
| :param sid: Session ID of the client.
| :param room: Room name.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the default namespace is used.
|
| save_session(self, sid, session, namespace=None)
| Store the user session for a client.
|
| :param sid: The session id of the client.
| :param session: The session dictionary.
| :param namespace: The Socket.IO namespace. If this argument is omitted
| the default namespace is used.
|
| send(self, data, to=None, room=None, skip_sid=None, namespace=None, callback=None, ignore_queue=False)
| Send a message to one or more connected clients.
|
| This function emits an event with the name ``'message'``. Use
| :func:`emit` to issue custom event names.
|
| :param data: The data to send to the client or clients. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
| :param to: The recipient of the message. This can be set to the
| session ID of a client to address only that client, to any
| any custom room created by the application to address all
| the clients in that room, or to a list of custom room
| names. If this argument is omitted the event is broadcasted
| to all connected clients.
| :param room: Alias for the ``to`` parameter.
| :param skip_sid: The session ID of a client to skip when broadcasting
| to a room or to all clients. This can be used to
| prevent a message from being sent to the sender. To
| skip multiple sids, pass a list.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the event is emitted to the
| default namespace.
| :param callback: If given, this function will be called to acknowledge
| the client has received the message. The arguments
| that will be passed to the function are those provided
| by the client. Callback functions can only be used
| when addressing an individual client.
| :param ignore_queue: Only used when a message queue is configured. If
| set to ``True``, the event is emitted to the
| clients directly, without going through the queue.
| This is more efficient, but only works when a
| single server process is used. It is recommended
| to always leave this parameter with its default
| value of ``False``.
|
| session(self, sid, namespace=None)
| Return the user session for a client with context manager syntax.
|
| :param sid: The session id of the client.
|
| This is a context manager that returns the user session dictionary for
| the client. Any changes that are made to this dictionary inside the
| context manager block are saved back to the session. Example usage::
|
| @sio.on('connect')
| def on_connect(sid, environ):
| username = authenticate_user(environ)
| if not username:
| return False
| with sio.session(sid) as session:
| session['username'] = username
|
| @sio.on('message')
| def on_message(sid, msg):
| with sio.session(sid) as session:
| print('received message from ', session['username'])
|
| shutdown(self)
| Stop Socket.IO background tasks.
|
| This method stops all background activity initiated by the Socket.IO
| server. It must be called before shutting down the web server.
|
| sleep(self, seconds=0)
| Sleep for the requested amount of time using the appropriate async
| model.
|
| This is a utility function that applications can use to put a task to
| sleep without having to worry about using the correct call for the
| selected async mode.
|
| start_background_task(self, target, *args, **kwargs)
| Start a background task using the appropriate async model.
|
| This is a utility function that applications can use to start a
| background task using the method that is compatible with the
| selected async mode.
|
| :param target: the target function to execute.
| :param args: arguments to pass to the function.
| :param kwargs: keyword arguments to pass to the function.
|
| This function returns an object that represents the background task,
| on which the ``join()`` methond can be invoked to wait for the task to
| complete.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.base_server.BaseServer:
|
| __init__(self, client_manager=None, logger=False, serializer='default', json=None, async_handlers=True, always_connect=False, namespaces=None, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| event(self, *args, **kwargs)
| Decorator to register an event handler.
|
| This is a simplified version of the ``on()`` method that takes the
| event name from the decorated function.
|
| Example usage::
|
| @sio.event
| def my_event(data):
| print('Received data: ', data)
|
| The above example is equivalent to::
|
| @sio.on('my_event')
| def my_event(data):
| print('Received data: ', data)
|
| A custom namespace can be given as an argument to the decorator::
|
| @sio.event(namespace='/test')
| def my_event(data):
| print('Received data: ', data)
|
| get_environ(self, sid, namespace=None)
| Return the WSGI environ dictionary for a client.
|
| :param sid: The session of the client.
| :param namespace: The Socket.IO namespace. If this argument is omitted
| the default namespace is used.
|
| is_asyncio_based(self)
|
| on(self, event, handler=None, namespace=None)
| Register an event handler.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used. The ``'*'`` event name
| can be used to define a catch-all event handler.
| :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. A catch-all namespace can be
| defined by passing ``'*'`` as the namespace.
|
| Example usage::
|
| # as a decorator:
| @sio.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)
| sio.send(sid, 'response')
| socket_io.on('message', namespace='/chat', handler=message_handler)
|
| The arguments passed to the handler function depend on the event type:
|
| - The ``'connect'`` event handler receives the ``sid`` (session ID) for
| the client and the WSGI environment dictionary as arguments.
| - The ``'disconnect'`` handler receives the ``sid`` for the client as
| only argument.
| - The ``'message'`` handler and handlers for custom event names receive
| the ``sid`` for the client and the message payload as arguments. Any
| values returned from a message handler will be passed to the client's
| acknowledgement callback function if it exists.
| - A catch-all event handler receives the event name as first argument,
| followed by any arguments specific to the event.
| - A catch-all namespace event handler receives the namespace as first
| argument, followed by any arguments specific to the event.
| - A combined catch-all namespace and catch-all event handler receives
| the event name as first argument and the namespace as second
| argument, followed by any arguments specific to the event.
|
| register_namespace(self, namespace_handler)
| Register a namespace handler object.
|
| :param namespace_handler: An instance of a :class:`Namespace`
| subclass that handles all the event traffic
| for a namespace.
|
| rooms(self, sid, namespace=None)
| Return the rooms a client is in.
|
| :param sid: Session ID of the client.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the default namespace is used.
|
| transport(self, sid, namespace=None)
| Return the name of the transport used by the client.
|
| The two possible values returned by this function are ``'polling'``
| and ``'websocket'``.
|
| :param sid: The session of the client.
| :param namespace: The Socket.IO namespace. If this argument is omitted
| the default namespace is used.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketio.base_server.BaseServer:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketio.base_server.BaseServer:
|
| reason = <class 'engineio.base_server.BaseServer.reason'>
| Disconnection reasons.
|
|
| reserved_events = ['connect', 'disconnect']
socketio.SimpleClient
Python Library Documentation: class SimpleClient in module socketio.simple_client
class SimpleClient(builtins.object)
| SimpleClient(*args, **kwargs)
|
| A Socket.IO client.
|
| This class implements a simple, yet fully compliant Socket.IO web client
| with support for websocket and long-polling transports.
|
| The positional and keyword arguments given in the constructor are passed
| to the underlying :func:`socketio.Client` object.
|
| Methods defined here:
|
| __enter__(self)
|
| __exit__(self, exc_type, exc_val, exc_tb)
|
| __init__(self, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| call(self, event, data=None, timeout=60)
| Emit an event to the server and wait for a response.
|
| This method issues an emit and waits for the server to provide a
| response or acknowledgement. If the response does not arrive before the
| timeout, then a ``TimeoutError`` exception is raised.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used.
| :param data: The data to send to the server. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
| :param timeout: The waiting timeout. If the timeout is reached before
| the server acknowledges the event, then a
| ``TimeoutError`` exception is raised.
|
| connect(self, url, headers={}, auth=None, transports=None, namespace='/', socketio_path='socket.io', wait_timeout=5)
| Connect to a Socket.IO server.
|
| :param url: The URL of the Socket.IO server. It can include custom
| query string parameters if required by the server. If a
| function is provided, the client will invoke it to obtain
| the URL each time a connection or reconnection is
| attempted.
| :param headers: A dictionary with custom headers to send with the
| connection request. If a function is provided, the
| client will invoke it to obtain the headers dictionary
| each time a connection or reconnection is attempted.
| :param auth: Authentication data passed to the server with the
| connection request, normally a dictionary with one or
| more string key/value pairs. If a function is provided,
| the client will invoke it to obtain the authentication
| data each time a connection or reconnection is attempted.
| :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 namespace: The namespace to connect to as a string. If not
| given, the default namespace ``/`` is used.
| :param socketio_path: The endpoint where the Socket.IO server is
| installed. The default value is appropriate for
| most cases.
| :param wait_timeout: How long the client should wait for the
| connection to be established. The default is 5
| seconds.
|
| disconnect(self)
| Disconnect from the server.
|
| emit(self, event, data=None)
| Emit an event to the server.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used.
| :param data: The data to send to the server. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
|
| This method schedules the event to be sent out and returns, without
| actually waiting for its delivery. In cases where the client needs to
| ensure that the event was received, :func:`socketio.SimpleClient.call`
| should be used instead.
|
| receive(self, timeout=None)
| Wait for an event from the server.
|
| :param timeout: The waiting timeout. If the timeout is reached before
| the server acknowledges the event, then a
| ``TimeoutError`` exception is raised.
|
| The return value is a list with the event name as the first element. If
| the server included arguments with the event, they are returned as
| additional list elements.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| sid
| The session ID received from the server.
|
| The session ID is not guaranteed to remain constant throughout the life
| of the connection, as reconnections can cause it to change.
|
| transport
| The name of the transport currently in use.
|
| The transport is returned as a string and can be one of ``polling``
| and ``websocket``.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| client_class = <class 'socketio.client.Client'>
| A Socket.IO client.
|
| This class implements a fully compliant Socket.IO web client with support
| for websocket and long-polling transports.
|
| :param reconnection: ``True`` if the client should automatically attempt to
| reconnect to the server after an interruption, or
| ``False`` to not reconnect. The default is ``True``.
| :param reconnection_attempts: How many reconnection attempts to issue
| before giving up, or 0 for infinite attempts.
| The default is 0.
| :param reconnection_delay: How long to wait in seconds before the first
| reconnection attempt. Each successive attempt
| doubles this delay.
| :param reconnection_delay_max: The maximum delay between reconnection
| attempts.
| :param randomization_factor: Randomization amount for each delay between
| reconnection attempts. The default is 0.5,
| which means that each delay is randomly
| adjusted by +/- 50%.
| :param logger: To enable logging set to ``True`` or pass a logger object to
| use. To disable logging set to ``False``. The default is
| ``False``. Note that fatal errors are logged even when
| ``logger`` is ``False``.
| :param serializer: The serialization method to use when transmitting
| packets. Valid values are ``'default'``, ``'pickle'``,
| ``'msgpack'`` and ``'cbor'``. Alternatively, a subclass
| of the :class:`Packet` class with custom implementations
| of the ``encode()`` and ``decode()`` methods can be
| provided. Client and server must use compatible
| serializers.
| :param json: An alternative JSON module to use for encoding and decoding
| packets. Custom json modules must have ``dumps`` and ``loads``
| functions that are compatible with the standard library
| versions. This is a process-wide setting, all instantiated
| servers and clients must use the same JSON module.
| :param handle_sigint: Set to ``True`` to automatically handle disconnection
| when the process is interrupted, or to ``False`` to
| leave interrupt handling to the calling application.
| Interrupt handling can only be enabled when the
| client instance is created in the main thread.
|
| The Engine.IO configuration supports the following settings:
|
| :param request_timeout: A timeout in seconds for requests. The default is
| 5 seconds.
| :param http_session: an initialized ``requests.Session`` object to be used
| when sending requests to the server. Use it if you
| need to add special client options such as proxy
| servers, SSL certificates, custom CA bundle, etc.
| :param ssl_verify: ``True`` to verify SSL certificates, or ``False`` to
| skip SSL certificate verification, allowing
| connections to servers with self signed certificates.
| The default is ``True``.
| :param websocket_extra_options: Dictionary containing additional keyword
| arguments passed to
| ``websocket.create_connection()``.
| :param engineio_logger: To enable Engine.IO logging set to ``True`` or pass
| a logger object to use. To disable logging set to
| ``False``. The default is ``False``. Note that
| fatal errors are logged even when
| ``engineio_logger`` is ``False``.
socketio.WSGIApp
Python Library Documentation: class WSGIApp in module socketio.middleware
class WSGIApp(engineio.middleware.WSGIApp)
| WSGIApp(socketio_app, wsgi_app=None, static_files=None, socketio_path='socket.io')
|
| WSGI middleware for Socket.IO.
|
| This middleware dispatches traffic to a Socket.IO application. It can also
| serve a list of static files to the client, or forward unrelated HTTP
| traffic to another WSGI application.
|
| :param socketio_app: The Socket.IO server. Must be an instance of the
| ``socketio.Server`` class.
| :param wsgi_app: The WSGI app that receives all other traffic.
| :param static_files: A dictionary with static file mapping rules. See the
| documentation for details on this argument.
| :param socketio_path: The endpoint where the Socket.IO application should
| be installed. The default value is appropriate for
| most cases.
|
| Example usage::
|
| import socketio
| import eventlet
| from . import wsgi_app
|
| sio = socketio.Server()
| app = socketio.WSGIApp(sio, wsgi_app)
| eventlet.wsgi.server(eventlet.listen(('', 8000)), app)
|
| Method resolution order:
| WSGIApp
| engineio.middleware.WSGIApp
| builtins.object
|
| Methods defined here:
|
| __init__(self, socketio_app, wsgi_app=None, static_files=None, socketio_path='socket.io')
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from engineio.middleware.WSGIApp:
|
| __call__(self, environ, start_response)
| Call self as a function.
|
| not_found(self, start_response)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from engineio.middleware.WSGIApp:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
socketio.ZmqManager
Python Library Documentation: class ZmqManager in module socketio.zmq_manager
class ZmqManager(socketio.pubsub_manager.PubSubManager)
| ZmqManager(url='zmq+tcp://localhost:5555+5556', channel='socketio', write_only=False, logger=None, json=None)
|
| zmq based client manager.
|
| NOTE: this zmq implementation should be considered experimental at this
| time. At this time, eventlet is required to use zmq.
|
| This class implements a zmq backend for event sharing across multiple
| processes. To use a zmq backend, initialize the :class:`Server` instance as
| follows::
|
| url = 'zmq+tcp://hostname:port1+port2'
| server = socketio.Server(client_manager=socketio.ZmqManager(url))
|
| :param url: The connection URL for the zmq message broker,
| which will need to be provided and running.
| :param channel: The channel name on which the server sends and receives
| notifications. Must be the same in all the servers.
| :param write_only: If set to ``True``, only initialize to emit events. The
| default of ``False`` initializes the class for emitting
| and receiving. A write-only instance can be used
| independently of the server to emit to clients from an
| external process.
| :param logger: a custom logger to log it. If not given, the server logger
| is used.
| :param json: An alternative JSON module to use for encoding and decoding
| packets. Custom json modules must have ``dumps`` and ``loads``
| functions that are compatible with the standard library
| versions. This setting is only used when ``write_only`` is set
| to ``True``. Otherwise the JSON module configured in the
| server is used.
|
| A zmq message broker must be running for the zmq_manager to work.
| you can write your own or adapt one from the following simple broker
| below::
|
| import zmq
|
| receiver = zmq.Context().socket(zmq.PULL)
| receiver.bind("tcp://*:5555")
|
| publisher = zmq.Context().socket(zmq.PUB)
| publisher.bind("tcp://*:5556")
|
| while True:
| publisher.send(receiver.recv())
|
| Method resolution order:
| ZmqManager
| socketio.pubsub_manager.PubSubManager
| socketio.manager.Manager
| socketio.base_manager.BaseManager
| builtins.object
|
| Methods defined here:
|
| __init__(self, url='zmq+tcp://localhost:5555+5556', channel='socketio', write_only=False, logger=None, json=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| zmq_listen(self)
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| name = 'zmq'
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.pubsub_manager.PubSubManager:
|
| can_disconnect(self, sid, namespace)
|
| close_room(self, room, namespace=None)
| Remove all participants from a room.
|
| disconnect(self, sid, namespace=None, **kwargs)
| Register a client disconnect from a namespace.
|
| emit(self, event, data, namespace=None, room=None, skip_sid=None, callback=None, to=None, **kwargs)
| Emit a message to a single client, a room, or all the clients
| connected to the namespace.
|
| This method takes care or propagating the message to all the servers
| that are connected through the message queue.
|
| The parameters are the same as in :meth:`.Server.emit`.
|
| enter_room(self, sid, namespace, room, eio_sid=None)
| Add a client to a room.
|
| initialize(self)
| Invoked before the first request is received. Subclasses can add
| their initialization code here.
|
| leave_room(self, sid, namespace, room)
| Remove a client from a room.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.manager.Manager:
|
| trigger_callback(self, sid, id, data)
| Invoke an application callback.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.base_manager.BaseManager:
|
| basic_close_room(self, room, namespace)
|
| basic_disconnect(self, sid, namespace, **kwargs)
|
| basic_enter_room(self, sid, namespace, room, eio_sid=None)
|
| basic_leave_room(self, sid, namespace, room)
|
| connect(self, eio_sid, namespace)
| Register a client connection to a namespace.
|
| eio_sid_from_sid(self, sid, namespace)
|
| get_namespaces(self)
| Return an iterable with the active namespace names.
|
| get_participants(self, namespace, room)
| Return an iterable with the active participants in a room.
|
| Note that in a multi-server scenario this method only returns the
| participants connect to the server in which the method is called. There
| is currently no functionality to assemble a complete list of users
| across multiple servers.
|
| get_rooms(self, sid, namespace)
| Return the rooms a client is in.
|
| is_connected(self, sid, namespace)
|
| pre_disconnect(self, sid, namespace)
| Put the client in the to-be-disconnected list.
|
| This allows the client data structures to be present while the
| disconnect handler is invoked, but still recognize the fact that the
| client is soon going away.
|
| set_server(self, server)
|
| sid_from_eio_sid(self, eio_sid, namespace)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketio.base_manager.BaseManager:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
socketio.asgi
Python Library Documentation: module socketio.asgi in socketio
NAME
socketio.asgi
CLASSES
engineio.async_drivers.asgi.ASGIApp(builtins.object)
ASGIApp
class ASGIApp(engineio.async_drivers.asgi.ASGIApp)
| ASGIApp(socketio_server, other_asgi_app=None, static_files=None, socketio_path='socket.io', on_startup=None, on_shutdown=None)
|
| ASGI application middleware for Socket.IO.
|
| This middleware dispatches traffic to an Socket.IO application. It can
| also serve a list of static files to the client, or forward unrelated
| HTTP traffic to another ASGI application.
|
| :param socketio_server: The Socket.IO server. Must be an instance of the
| ``socketio.AsyncServer`` class.
| :param static_files: A dictionary with static file mapping rules. See the
| documentation for details on this argument.
| :param other_asgi_app: A separate ASGI app that receives all other traffic.
| :param socketio_path: The endpoint where the Socket.IO application should
| be installed. The default value is appropriate for
| most cases. With a value of ``None``, all incoming
| traffic is directed to the Socket.IO server, with the
| assumption that routing, if necessary, is handled by
| a different layer. When this option is set to
| ``None``, ``static_files`` and ``other_asgi_app`` are
| ignored.
| :param on_startup: function to be called on application startup; can be
| coroutine
| :param on_shutdown: function to be called on application shutdown; can be
| coroutine
|
| Example usage::
|
| import socketio
| import uvicorn
|
| sio = socketio.AsyncServer()
| app = socketio.ASGIApp(sio, static_files={
| '/': 'index.html',
| '/static': './public',
| })
| uvicorn.run(app, host='127.0.0.1', port=5000)
|
| Method resolution order:
| ASGIApp
| engineio.async_drivers.asgi.ASGIApp
| builtins.object
|
| Methods defined here:
|
| __init__(self, socketio_server, other_asgi_app=None, static_files=None, socketio_path='socket.io', on_startup=None, on_shutdown=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from engineio.async_drivers.asgi.ASGIApp:
|
| async __call__(self, scope, receive, send)
| Call self as a function.
|
| async lifespan(self, scope, receive, send)
|
| async not_found(self, receive, send)
| Return a 404 Not Found error to the client.
|
| async serve_static_file(self, static_file, receive, send)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from engineio.async_drivers.asgi.ASGIApp:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\socketio\asgi.py
socketio.async_aiopika_manager
Python Library Documentation: module socketio.async_aiopika_manager in socketio
NAME
socketio.async_aiopika_manager
CLASSES
socketio.async_pubsub_manager.AsyncPubSubManager(socketio.async_manager.AsyncManager)
AsyncAioPikaManager
class AsyncAioPikaManager(socketio.async_pubsub_manager.AsyncPubSubManager)
| AsyncAioPikaManager(url='amqp://guest:guest@localhost:5672//', channel='socketio', write_only=False, logger=None, json=None)
|
| Client manager that uses aio_pika for inter-process messaging under
| asyncio.
|
| This class implements a client manager backend for event sharing across
| multiple processes, using RabbitMQ
|
| To use a aio_pika backend, initialize the :class:`Server` instance as
| follows::
|
| url = 'amqp://user:password@hostname:port//'
| server = socketio.Server(client_manager=socketio.AsyncAioPikaManager(
| url))
|
| :param url: The connection URL for the backend messaging queue. Example
| connection URLs are ``'amqp://guest:guest@localhost:5672//'``
| for RabbitMQ.
| :param channel: The channel name on which the server sends and receives
| notifications. Must be the same in all the servers.
| With this manager, the channel name is the exchange name
| in rabbitmq
| :param write_only: If set to ``True``, only initialize to emit events. The
| default of ``False`` initializes the class for emitting
| and receiving. A write-only instance can be used
| independently of the server to emit to clients from an
| external process.
| :param logger: a custom logger to log it. If not given, the server logger
| is used.
| :param json: An alternative JSON module to use for encoding and decoding
| packets. Custom json modules must have ``dumps`` and ``loads``
| functions that are compatible with the standard library
| versions. This setting is only used when ``write_only`` is set
| to ``True``. Otherwise the JSON module configured in the
| server is used.
|
| Method resolution order:
| AsyncAioPikaManager
| socketio.async_pubsub_manager.AsyncPubSubManager
| socketio.async_manager.AsyncManager
| socketio.base_manager.BaseManager
| builtins.object
|
| Methods defined here:
|
| __init__(self, url='amqp://guest:guest@localhost:5672//', channel='socketio', write_only=False, logger=None, json=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| name = 'asyncaiopika'
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.async_pubsub_manager.AsyncPubSubManager:
|
| async can_disconnect(self, sid, namespace)
|
| async close_room(self, room, namespace=None)
| Remove all participants from a room.
|
| Note: this method is a coroutine.
|
| async disconnect(self, sid, namespace, **kwargs)
| Disconnect a client.
|
| Note: this method is a coroutine.
|
| async emit(self, event, data, namespace=None, room=None, skip_sid=None, callback=None, to=None, **kwargs)
| Emit a message to a single client, a room, or all the clients
| connected to the namespace.
|
| This method takes care or propagating the message to all the servers
| that are connected through the message queue.
|
| The parameters are the same as in :meth:`.Server.emit`.
|
| Note: this method is a coroutine.
|
| async enter_room(self, sid, namespace, room, eio_sid=None)
| Add a client to a room.
|
| Note: this method is a coroutine.
|
| initialize(self)
| Invoked before the first request is received. Subclasses can add
| their initialization code here.
|
| async leave_room(self, sid, namespace, room)
| Remove a client from a room.
|
| Note: this method is a coroutine.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.async_manager.AsyncManager:
|
| async connect(self, eio_sid, namespace)
| Register a client connection to a namespace.
|
| Note: this method is a coroutine.
|
| async trigger_callback(self, sid, id, data)
| Invoke an application callback.
|
| Note: this method is a coroutine.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.base_manager.BaseManager:
|
| basic_close_room(self, room, namespace)
|
| basic_disconnect(self, sid, namespace, **kwargs)
|
| basic_enter_room(self, sid, namespace, room, eio_sid=None)
|
| basic_leave_room(self, sid, namespace, room)
|
| eio_sid_from_sid(self, sid, namespace)
|
| get_namespaces(self)
| Return an iterable with the active namespace names.
|
| get_participants(self, namespace, room)
| Return an iterable with the active participants in a room.
|
| Note that in a multi-server scenario this method only returns the
| participants connect to the server in which the method is called. There
| is currently no functionality to assemble a complete list of users
| across multiple servers.
|
| get_rooms(self, sid, namespace)
| Return the rooms a client is in.
|
| is_connected(self, sid, namespace)
|
| pre_disconnect(self, sid, namespace)
| Put the client in the to-be-disconnected list.
|
| This allows the client data structures to be present while the
| disconnect handler is invoked, but still recognize the fact that the
| client is soon going away.
|
| set_server(self, server)
|
| sid_from_eio_sid(self, eio_sid, namespace)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketio.base_manager.BaseManager:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
DATA
aio_pika = None
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\socketio\async_aiopika_manager.py
socketio.async_client
Python Library Documentation: module socketio.async_client in socketio
NAME
socketio.async_client
CLASSES
socketio.base_client.BaseClient(builtins.object)
AsyncClient
class AsyncClient(socketio.base_client.BaseClient)
| AsyncClient(reconnection=True, reconnection_attempts=0, reconnection_delay=1, reconnection_delay_max=5, randomization_factor=0.5, logger=False, serializer='default', json=None, handle_sigint=True, **kwargs)
|
| A Socket.IO client for asyncio.
|
| This class implements a fully compliant Socket.IO web client with support
| for websocket and long-polling transports.
|
| :param reconnection: ``True`` if the client should automatically attempt to
| reconnect to the server after an interruption, or
| ``False`` to not reconnect. The default is ``True``.
| :param reconnection_attempts: How many reconnection attempts to issue
| before giving up, or 0 for infinite attempts.
| The default is 0.
| :param reconnection_delay: How long to wait in seconds before the first
| reconnection attempt. Each successive attempt
| doubles this delay.
| :param reconnection_delay_max: The maximum delay between reconnection
| attempts.
| :param randomization_factor: Randomization amount for each delay between
| reconnection attempts. The default is 0.5,
| which means that each delay is randomly
| adjusted by +/- 50%.
| :param logger: To enable logging set to ``True`` or pass a logger object to
| use. To disable logging set to ``False``. The default is
| ``False``. Note that fatal errors are logged even when
| ``logger`` is ``False``.
| :param json: An alternative JSON module to use for encoding and decoding
| packets. Custom json modules must have ``dumps`` and ``loads``
| functions that are compatible with the standard library
| versions. This is a process-wide setting, all instantiated
| servers and clients must use the same JSON module.
| :param handle_sigint: Set to ``True`` to automatically handle disconnection
| when the process is interrupted, or to ``False`` to
| leave interrupt handling to the calling application.
| Interrupt handling can only be enabled when the
| client instance is created in the main thread.
|
| The Engine.IO configuration supports the following settings:
|
| :param request_timeout: A timeout in seconds for requests. The default is
| 5 seconds.
| :param http_session: an initialized ``aiohttp.ClientSession`` object to be
| used when sending requests to the server. Use it if
| you need to add special client options such as proxy
| servers, SSL certificates, custom CA bundle, etc.
| :param ssl_verify: ``True`` to verify SSL certificates, or ``False`` to
| skip SSL certificate verification, allowing
| connections to servers with self signed certificates.
| The default is ``True``.
| :param websocket_extra_options: Dictionary containing additional keyword
| arguments passed to
| ``websocket.create_connection()``.
| :param engineio_logger: To enable Engine.IO logging set to ``True`` or pass
| a logger object to use. To disable logging set to
| ``False``. The default is ``False``. Note that
| fatal errors are logged even when
| ``engineio_logger`` is ``False``.
|
| Method resolution order:
| AsyncClient
| socketio.base_client.BaseClient
| builtins.object
|
| Methods defined here:
|
| async call(self, event, data=None, namespace=None, timeout=60)
| Emit a custom event to the server and wait for the response.
|
| This method issues an emit with a callback and waits for the callback
| to be invoked before returning. If the callback isn't invoked before
| the timeout, then a ``TimeoutError`` exception is raised. If the
| Socket.IO connection drops during the wait, this method still waits
| until the specified timeout.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used.
| :param data: The data to send to the server. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the event is emitted to the
| default namespace.
| :param timeout: The waiting timeout. If the timeout is reached before
| the server acknowledges the event, then a
| ``TimeoutError`` exception is raised.
|
| Note: this method is not designed to be used concurrently. If multiple
| tasks are emitting at the same time on the same client connection, then
| messages composed of multiple packets may end up being sent in an
| incorrect sequence. Use standard concurrency solutions (such as a Lock
| object) to prevent this situation.
|
| Note 2: this method is a coroutine.
|
| async connect(self, url, headers={}, auth=None, transports=None, namespaces=None, socketio_path='socket.io', wait=True, wait_timeout=1, retry=False)
| Connect to a Socket.IO server.
|
| :param url: The URL of the Socket.IO server. It can include custom
| query string parameters if required by the server. If a
| function is provided, the client will invoke it to obtain
| the URL each time a connection or reconnection is
| attempted.
| :param headers: A dictionary with custom headers to send with the
| connection request. If a function is provided, the
| client will invoke it to obtain the headers dictionary
| each time a connection or reconnection is attempted.
| :param auth: Authentication data passed to the server with the
| connection request, normally a dictionary with one or
| more string key/value pairs. If a function is provided,
| the client will invoke it to obtain the authentication
| data each time a connection or reconnection is attempted.
| :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.
| :param wait: if set to ``True`` (the default) the call only returns
| when all the namespaces are connected. If set to
| ``False``, the call returns as soon as the Engine.IO
| transport is connected, and the namespaces will connect
| in the background.
| :param wait_timeout: How long the client should wait for the
| connection. The default is 1 second. This
| argument is only considered when ``wait`` is set
| to ``True``.
| :param retry: Apply the reconnection logic if the initial connection
| attempt fails. The default is ``False``.
|
| Note: this method is a coroutine.
|
| Example usage::
|
| sio = socketio.AsyncClient()
| await sio.connect('http://localhost:5000')
|
| async disconnect(self)
| Disconnect from the server.
|
| Note: this method is a coroutine.
|
| async emit(self, event, data=None, namespace=None, callback=None)
| Emit a custom event to the server.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used.
| :param data: The data to send to the server. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the event is emitted to the
| default namespace.
| :param callback: If given, this function will be called to acknowledge
| the server has received the message. The arguments
| that will be passed to the function are those provided
| by the server.
|
| Note: this method is not designed to be used concurrently. If multiple
| tasks are emitting at the same time on the same client connection, then
| messages composed of multiple packets may end up being sent in an
| incorrect sequence. Use standard concurrency solutions (such as a Lock
| object) to prevent this situation.
|
| Note 2: this method is a coroutine.
|
| is_asyncio_based(self)
|
| async send(self, data, namespace=None, callback=None)
| Send a message to the server.
|
| This function emits an event with the name ``'message'``. Use
| :func:`emit` to issue custom event names.
|
| :param data: The data to send to the server. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the event is emitted to the
| default namespace.
| :param callback: If given, this function will be called to acknowledge
| the server has received the message. The arguments
| that will be passed to the function are those provided
| by the server.
|
| Note: this method is a coroutine.
|
| async shutdown(self)
| Stop the client.
|
| If the client is connected to a server, it is disconnected. If the
| client is attempting to reconnect to server, the reconnection attempts
| are stopped. If the client is not connected to a server and is not
| attempting to reconnect, then this function does nothing.
|
| async sleep(self, seconds=0)
| Sleep for the requested amount of time using the appropriate async
| model.
|
| This is a utility function that applications can use to put a task to
| sleep without having to worry about using the correct call for the
| selected async mode.
|
| Note: this method is a coroutine.
|
| start_background_task(self, target, *args, **kwargs)
| Start a background task using the appropriate async model.
|
| This is a utility function that applications can use to start a
| background task using the method that is compatible with the
| selected async mode.
|
| :param target: the target function to execute.
| :param args: arguments to pass to the function.
| :param kwargs: keyword arguments to pass to the function.
|
| The return value is a ``asyncio.Task`` object.
|
| async wait(self)
| Wait until the connection with the server ends.
|
| Client applications can use this function to block the main thread
| during the life of the connection.
|
| Note: this method is a coroutine.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.base_client.BaseClient:
|
| __init__(self, reconnection=True, reconnection_attempts=0, reconnection_delay=1, reconnection_delay_max=5, randomization_factor=0.5, logger=False, serializer='default', json=None, handle_sigint=True, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| event(self, *args, **kwargs)
| Decorator to register an event handler.
|
| This is a simplified version of the ``on()`` method that takes the
| event name from the decorated function.
|
| Example usage::
|
| @sio.event
| def my_event(data):
| print('Received data: ', data)
|
| The above example is equivalent to::
|
| @sio.on('my_event')
| def my_event(data):
| print('Received data: ', data)
|
| A custom namespace can be given as an argument to the decorator::
|
| @sio.event(namespace='/test')
| def my_event(data):
| print('Received data: ', data)
|
| get_sid(self, namespace=None)
| Return the ``sid`` associated with a connection.
|
| :param namespace: The Socket.IO namespace. If this argument is omitted
| the handler is associated with the default
| namespace. Note that unlike previous versions, the
| current version of the Socket.IO protocol uses
| different ``sid`` values per namespace.
|
| This method returns the ``sid`` for the requested namespace as a
| string.
|
| on(self, event, handler=None, namespace=None)
| Register an event handler.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used. The ``'*'`` event name
| can be used to define a catch-all event handler.
| :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. A catch-all namespace can be
| defined by passing ``'*'`` as the namespace.
|
| Example usage::
|
| # as a decorator:
| @sio.on('connect')
| def connect_handler():
| print('Connected!')
|
| # as a method:
| def message_handler(msg):
| print('Received message: ', msg)
| sio.send( 'response')
| sio.on('message', message_handler)
|
| The arguments passed to the handler function depend on the event type:
|
| - The ``'connect'`` event handler does not take arguments.
| - The ``'disconnect'`` event handler does not take arguments.
| - The ``'message'`` handler and handlers for custom event names receive
| the message payload as only argument. Any values returned from a
| message handler will be passed to the client's acknowledgement
| callback function if it exists.
| - A catch-all event handler receives the event name as first argument,
| followed by any arguments specific to the event.
| - A catch-all namespace event handler receives the namespace as first
| argument, followed by any arguments specific to the event.
| - A combined catch-all namespace and catch-all event handler receives
| the event name as first argument and the namespace as second
| argument, followed by any arguments specific to the event.
|
| register_namespace(self, namespace_handler)
| Register a namespace handler object.
|
| :param namespace_handler: An instance of a :class:`Namespace`
| subclass that handles all the event traffic
| for a namespace.
|
| transport(self)
| Return the name of the transport used by the client.
|
| The two possible values returned by this function are ``'polling'``
| and ``'websocket'``.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketio.base_client.BaseClient:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketio.base_client.BaseClient:
|
| reason = <class 'engineio.base_client.BaseClient.reason'>
| Disconnection reasons.
|
|
| reserved_events = ['connect', 'connect_error', 'disconnect', '__discon...
DATA
default_logger = <Logger socketio.client (WARNING)>
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\socketio\async_client.py
socketio.async_manager
Python Library Documentation: module socketio.async_manager in socketio
NAME
socketio.async_manager
CLASSES
socketio.base_manager.BaseManager(builtins.object)
AsyncManager
class AsyncManager(socketio.base_manager.BaseManager)
| Manage a client list for an asyncio server.
|
| Method resolution order:
| AsyncManager
| socketio.base_manager.BaseManager
| builtins.object
|
| Methods defined here:
|
| async can_disconnect(self, sid, namespace)
|
| async close_room(self, room, namespace)
| Remove all participants from a room.
|
| Note: this method is a coroutine.
|
| async connect(self, eio_sid, namespace)
| Register a client connection to a namespace.
|
| Note: this method is a coroutine.
|
| async disconnect(self, sid, namespace, **kwargs)
| Disconnect a client.
|
| Note: this method is a coroutine.
|
| async emit(self, event, data, namespace, room=None, skip_sid=None, callback=None, to=None, **kwargs)
| Emit a message to a single client, a room, or all the clients
| connected to the namespace.
|
| Note: this method is a coroutine.
|
| async enter_room(self, sid, namespace, room, eio_sid=None)
| Add a client to a room.
|
| Note: this method is a coroutine.
|
| async leave_room(self, sid, namespace, room)
| Remove a client from a room.
|
| Note: this method is a coroutine.
|
| async trigger_callback(self, sid, id, data)
| Invoke an application callback.
|
| Note: this method is a coroutine.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.base_manager.BaseManager:
|
| __init__(self)
| Initialize self. See help(type(self)) for accurate signature.
|
| basic_close_room(self, room, namespace)
|
| basic_disconnect(self, sid, namespace, **kwargs)
|
| basic_enter_room(self, sid, namespace, room, eio_sid=None)
|
| basic_leave_room(self, sid, namespace, room)
|
| eio_sid_from_sid(self, sid, namespace)
|
| get_namespaces(self)
| Return an iterable with the active namespace names.
|
| get_participants(self, namespace, room)
| Return an iterable with the active participants in a room.
|
| Note that in a multi-server scenario this method only returns the
| participants connect to the server in which the method is called. There
| is currently no functionality to assemble a complete list of users
| across multiple servers.
|
| get_rooms(self, sid, namespace)
| Return the rooms a client is in.
|
| initialize(self)
| Invoked before the first request is received. Subclasses can add
| their initialization code here.
|
| is_connected(self, sid, namespace)
|
| pre_disconnect(self, sid, namespace)
| Put the client in the to-be-disconnected list.
|
| This allows the client data structures to be present while the
| disconnect handler is invoked, but still recognize the fact that the
| client is soon going away.
|
| set_server(self, server)
|
| sid_from_eio_sid(self, eio_sid, namespace)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketio.base_manager.BaseManager:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\socketio\async_manager.py
socketio.async_namespace
Python Library Documentation: module socketio.async_namespace in socketio
NAME
socketio.async_namespace
CLASSES
socketio.base_namespace.BaseClientNamespace(socketio.base_namespace.BaseNamespace)
AsyncClientNamespace
socketio.base_namespace.BaseServerNamespace(socketio.base_namespace.BaseNamespace)
AsyncNamespace
class AsyncClientNamespace(socketio.base_namespace.BaseClientNamespace)
| AsyncClientNamespace(namespace=None)
|
| Base class for asyncio client-side class-based namespaces.
|
| A class-based namespace is a class that contains all the event handlers
| for a Socket.IO namespace. The event handlers are methods of the class
| with the prefix ``on_``, such as ``on_connect``, ``on_disconnect``,
| ``on_message``, ``on_json``, and so on. These can be regular functions or
| coroutines.
|
| :param namespace: The Socket.IO namespace to be used with all the event
| handlers defined in this class. If this argument is
| omitted, the default namespace is used.
|
| Method resolution order:
| AsyncClientNamespace
| socketio.base_namespace.BaseClientNamespace
| socketio.base_namespace.BaseNamespace
| builtins.object
|
| Methods defined here:
|
| async call(self, event, data=None, namespace=None, timeout=None)
| Emit a custom event to the server and wait for the response.
|
| The only difference with the :func:`socketio.Client.call` method is
| that when the ``namespace`` argument is not given the namespace
| associated with the class is used.
|
| async disconnect(self)
| Disconnect a client.
|
| The only difference with the :func:`socketio.Client.disconnect` method
| is that when the ``namespace`` argument is not given the namespace
| associated with the class is used.
|
| Note: this method is a coroutine.
|
| async emit(self, event, data=None, namespace=None, callback=None)
| Emit a custom event to the server.
|
| The only difference with the :func:`socketio.Client.emit` method is
| that when the ``namespace`` argument is not given the namespace
| associated with the class is used.
|
| Note: this method is a coroutine.
|
| is_asyncio_based(self)
|
| async send(self, data, namespace=None, callback=None)
| Send a message to the server.
|
| The only difference with the :func:`socketio.Client.send` method is
| that when the ``namespace`` argument is not given the namespace
| associated with the class is used.
|
| Note: this method is a coroutine.
|
| async trigger_event(self, event, *args)
| Dispatch an event to the proper handler method.
|
| In the most common usage, this method is not overloaded by subclasses,
| as it performs the routing of events to methods. However, this
| method can be overridden if special dispatching rules are needed, or if
| having a single method that catches all events is desired.
|
| Note: this method is a coroutine.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.base_namespace.BaseClientNamespace:
|
| __init__(self, namespace=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketio.base_namespace.BaseNamespace:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class AsyncNamespace(socketio.base_namespace.BaseServerNamespace)
| AsyncNamespace(namespace=None)
|
| Base class for asyncio server-side class-based namespaces.
|
| A class-based namespace is a class that contains all the event handlers
| for a Socket.IO namespace. The event handlers are methods of the class
| with the prefix ``on_``, such as ``on_connect``, ``on_disconnect``,
| ``on_message``, ``on_json``, and so on. These can be regular functions or
| coroutines.
|
| :param namespace: The Socket.IO namespace to be used with all the event
| handlers defined in this class. If this argument is
| omitted, the default namespace is used.
|
| Method resolution order:
| AsyncNamespace
| socketio.base_namespace.BaseServerNamespace
| socketio.base_namespace.BaseNamespace
| builtins.object
|
| Methods defined here:
|
| async call(self, event, data=None, to=None, sid=None, namespace=None, timeout=None, ignore_queue=False)
| Emit a custom event to a client and wait for the response.
|
| The only difference with the :func:`socketio.Server.call` method is
| that when the ``namespace`` argument is not given the namespace
| associated with the class is used.
|
| async close_room(self, room, namespace=None)
| Close a room.
|
| The only difference with the :func:`socketio.Server.close_room` method
| is that when the ``namespace`` argument is not given the namespace
| associated with the class is used.
|
| Note: this method is a coroutine.
|
| async disconnect(self, sid, namespace=None)
| Disconnect a client.
|
| The only difference with the :func:`socketio.Server.disconnect` method
| is that when the ``namespace`` argument is not given the namespace
| associated with the class is used.
|
| Note: this method is a coroutine.
|
| async emit(self, event, data=None, to=None, room=None, skip_sid=None, namespace=None, callback=None, ignore_queue=False)
| Emit a custom event to one or more connected clients.
|
| The only difference with the :func:`socketio.Server.emit` method is
| that when the ``namespace`` argument is not given the namespace
| associated with the class is used.
|
| Note: this method is a coroutine.
|
| async enter_room(self, sid, room, namespace=None)
| Enter a room.
|
| The only difference with the :func:`socketio.Server.enter_room` method
| is that when the ``namespace`` argument is not given the namespace
| associated with the class is used.
|
| Note: this method is a coroutine.
|
| async get_session(self, sid, namespace=None)
| Return the user session for a client.
|
| The only difference with the :func:`socketio.Server.get_session`
| method is that when the ``namespace`` argument is not given the
| namespace associated with the class is used.
|
| Note: this method is a coroutine.
|
| is_asyncio_based(self)
|
| async leave_room(self, sid, room, namespace=None)
| Leave a room.
|
| The only difference with the :func:`socketio.Server.leave_room` method
| is that when the ``namespace`` argument is not given the namespace
| associated with the class is used.
|
| Note: this method is a coroutine.
|
| async save_session(self, sid, session, namespace=None)
| Store the user session for a client.
|
| The only difference with the :func:`socketio.Server.save_session`
| method is that when the ``namespace`` argument is not given the
| namespace associated with the class is used.
|
| Note: this method is a coroutine.
|
| async send(self, data, to=None, room=None, skip_sid=None, namespace=None, callback=None, ignore_queue=False)
| Send a message to one or more connected clients.
|
| The only difference with the :func:`socketio.Server.send` method is
| that when the ``namespace`` argument is not given the namespace
| associated with the class is used.
|
| Note: this method is a coroutine.
|
| session(self, sid, namespace=None)
| Return the user session for a client with context manager syntax.
|
| The only difference with the :func:`socketio.Server.session` method is
| that when the ``namespace`` argument is not given the namespace
| associated with the class is used.
|
| async trigger_event(self, event, *args)
| Dispatch an event to the proper handler method.
|
| In the most common usage, this method is not overloaded by subclasses,
| as it performs the routing of events to methods. However, this
| method can be overridden if special dispatching rules are needed, or if
| having a single method that catches all events is desired.
|
| Note: this method is a coroutine.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.base_namespace.BaseServerNamespace:
|
| __init__(self, namespace=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| rooms(self, sid, namespace=None)
| Return the rooms a client is in.
|
| The only difference with the :func:`socketio.Server.rooms` method is
| that when the ``namespace`` argument is not given the namespace
| associated with the class is used.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketio.base_namespace.BaseNamespace:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\socketio\async_namespace.py
socketio.async_pubsub_manager
Python Library Documentation: module socketio.async_pubsub_manager in socketio
NAME
socketio.async_pubsub_manager
CLASSES
socketio.async_manager.AsyncManager(socketio.base_manager.BaseManager)
AsyncPubSubManager
class AsyncPubSubManager(socketio.async_manager.AsyncManager)
| AsyncPubSubManager(channel='socketio', write_only=False, logger=None, json=None)
|
| Manage a client list attached to a pub/sub backend under asyncio.
|
| This is a base class that enables multiple servers to share the list of
| clients, with the servers communicating events through a pub/sub backend.
| The use of a pub/sub backend also allows any client connected to the
| backend to emit events addressed to Socket.IO clients.
|
| The actual backends must be implemented by subclasses, this class only
| provides a pub/sub generic framework for asyncio applications.
|
| :param channel: The channel name on which the server sends and receives
| notifications.
| :param write_only: If set to ``True``, only initialize to emit events. The
| default of ``False`` initializes the class for emitting
| and receiving. A write-only instance can be used
| independently of the server to emit to clients from an
| external process.
| :param logger: a custom logger to log it. If not given, the server logger
| is used.
| :param json: An alternative JSON module to use for encoding and decoding
| packets. Custom json modules must have ``dumps`` and ``loads``
| functions that are compatible with the standard library
| versions. This setting is only used when ``write_only`` is set
| to ``True``. Otherwise the JSON module configured in the
| server is used.
|
| Method resolution order:
| AsyncPubSubManager
| socketio.async_manager.AsyncManager
| socketio.base_manager.BaseManager
| builtins.object
|
| Methods defined here:
|
| __init__(self, channel='socketio', write_only=False, logger=None, json=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| async can_disconnect(self, sid, namespace)
|
| async close_room(self, room, namespace=None)
| Remove all participants from a room.
|
| Note: this method is a coroutine.
|
| async disconnect(self, sid, namespace, **kwargs)
| Disconnect a client.
|
| Note: this method is a coroutine.
|
| async emit(self, event, data, namespace=None, room=None, skip_sid=None, callback=None, to=None, **kwargs)
| Emit a message to a single client, a room, or all the clients
| connected to the namespace.
|
| This method takes care or propagating the message to all the servers
| that are connected through the message queue.
|
| The parameters are the same as in :meth:`.Server.emit`.
|
| Note: this method is a coroutine.
|
| async enter_room(self, sid, namespace, room, eio_sid=None)
| Add a client to a room.
|
| Note: this method is a coroutine.
|
| initialize(self)
| Invoked before the first request is received. Subclasses can add
| their initialization code here.
|
| async leave_room(self, sid, namespace, room)
| Remove a client from a room.
|
| Note: this method is a coroutine.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| name = 'asyncpubsub'
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.async_manager.AsyncManager:
|
| async connect(self, eio_sid, namespace)
| Register a client connection to a namespace.
|
| Note: this method is a coroutine.
|
| async trigger_callback(self, sid, id, data)
| Invoke an application callback.
|
| Note: this method is a coroutine.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.base_manager.BaseManager:
|
| basic_close_room(self, room, namespace)
|
| basic_disconnect(self, sid, namespace, **kwargs)
|
| basic_enter_room(self, sid, namespace, room, eio_sid=None)
|
| basic_leave_room(self, sid, namespace, room)
|
| eio_sid_from_sid(self, sid, namespace)
|
| get_namespaces(self)
| Return an iterable with the active namespace names.
|
| get_participants(self, namespace, room)
| Return an iterable with the active participants in a room.
|
| Note that in a multi-server scenario this method only returns the
| participants connect to the server in which the method is called. There
| is currently no functionality to assemble a complete list of users
| across multiple servers.
|
| get_rooms(self, sid, namespace)
| Return the rooms a client is in.
|
| is_connected(self, sid, namespace)
|
| pre_disconnect(self, sid, namespace)
| Put the client in the to-be-disconnected list.
|
| This allows the client data structures to be present while the
| disconnect handler is invoked, but still recognize the fact that the
| client is soon going away.
|
| set_server(self, server)
|
| sid_from_eio_sid(self, eio_sid, namespace)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketio.base_manager.BaseManager:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\socketio\async_pubsub_manager.py
socketio.async_redis_manager
Python Library Documentation: module socketio.async_redis_manager in socketio
NAME
socketio.async_redis_manager
CLASSES
socketio.async_pubsub_manager.AsyncPubSubManager(socketio.async_manager.AsyncManager)
AsyncRedisManager
class AsyncRedisManager(socketio.async_pubsub_manager.AsyncPubSubManager)
| AsyncRedisManager(url='redis://localhost:6379/0', channel='socketio', write_only=False, logger=None, json=None, redis_options=None)
|
| Redis based client manager for asyncio servers.
|
| This class implements a Redis backend for event sharing across multiple
| processes.
|
| To use a Redis backend, initialize the :class:`AsyncServer` instance as
| follows::
|
| url = 'redis://hostname:port/0'
| server = socketio.AsyncServer(
| client_manager=socketio.AsyncRedisManager(url))
|
| :param url: The connection URL for the Redis server. For a default Redis
| store running on the same host, use ``redis://``. To use a
| TLS connection, use ``rediss://``. To use Redis Sentinel, use
| ``redis+sentinel://`` with a comma-separated list of hosts
| and the service name after the db in the URL path. Example:
| ``redis+sentinel://user:pw@host1:1234,host2:2345/0/myredis``.
| :param channel: The channel name on which the server sends and receives
| notifications. Must be the same in all the servers.
| :param write_only: If set to ``True``, only initialize to emit events. The
| default of ``False`` initializes the class for emitting
| and receiving. A write-only instance can be used
| independently of the server to emit to clients from an
| external process.
| :param logger: a custom logger to log it. If not given, the server logger
| is used.
| :param json: An alternative JSON module to use for encoding and decoding
| packets. Custom json modules must have ``dumps`` and ``loads``
| functions that are compatible with the standard library
| versions. This setting is only used when ``write_only`` is set
| to ``True``. Otherwise the JSON module configured in the
| server is used.
| :param redis_options: additional keyword arguments to be passed to
| ``Redis.from_url()`` or ``Sentinel()``.
|
| Method resolution order:
| AsyncRedisManager
| socketio.async_pubsub_manager.AsyncPubSubManager
| socketio.async_manager.AsyncManager
| socketio.base_manager.BaseManager
| builtins.object
|
| Methods defined here:
|
| __init__(self, url='redis://localhost:6379/0', channel='socketio', write_only=False, logger=None, json=None, redis_options=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| name = 'aioredis'
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.async_pubsub_manager.AsyncPubSubManager:
|
| async can_disconnect(self, sid, namespace)
|
| async close_room(self, room, namespace=None)
| Remove all participants from a room.
|
| Note: this method is a coroutine.
|
| async disconnect(self, sid, namespace, **kwargs)
| Disconnect a client.
|
| Note: this method is a coroutine.
|
| async emit(self, event, data, namespace=None, room=None, skip_sid=None, callback=None, to=None, **kwargs)
| Emit a message to a single client, a room, or all the clients
| connected to the namespace.
|
| This method takes care or propagating the message to all the servers
| that are connected through the message queue.
|
| The parameters are the same as in :meth:`.Server.emit`.
|
| Note: this method is a coroutine.
|
| async enter_room(self, sid, namespace, room, eio_sid=None)
| Add a client to a room.
|
| Note: this method is a coroutine.
|
| initialize(self)
| Invoked before the first request is received. Subclasses can add
| their initialization code here.
|
| async leave_room(self, sid, namespace, room)
| Remove a client from a room.
|
| Note: this method is a coroutine.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.async_manager.AsyncManager:
|
| async connect(self, eio_sid, namespace)
| Register a client connection to a namespace.
|
| Note: this method is a coroutine.
|
| async trigger_callback(self, sid, id, data)
| Invoke an application callback.
|
| Note: this method is a coroutine.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.base_manager.BaseManager:
|
| basic_close_room(self, room, namespace)
|
| basic_disconnect(self, sid, namespace, **kwargs)
|
| basic_enter_room(self, sid, namespace, room, eio_sid=None)
|
| basic_leave_room(self, sid, namespace, room)
|
| eio_sid_from_sid(self, sid, namespace)
|
| get_namespaces(self)
| Return an iterable with the active namespace names.
|
| get_participants(self, namespace, room)
| Return an iterable with the active participants in a room.
|
| Note that in a multi-server scenario this method only returns the
| participants connect to the server in which the method is called. There
| is currently no functionality to assemble a complete list of users
| across multiple servers.
|
| get_rooms(self, sid, namespace)
| Return the rooms a client is in.
|
| is_connected(self, sid, namespace)
|
| pre_disconnect(self, sid, namespace)
| Put the client in the to-be-disconnected list.
|
| This allows the client data structures to be present while the
| disconnect handler is invoked, but still recognize the fact that the
| client is soon going away.
|
| set_server(self, server)
|
| sid_from_eio_sid(self, eio_sid, namespace)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketio.base_manager.BaseManager:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
DATA
ValkeyError = None
aiovalkey = None
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\socketio\async_redis_manager.py
socketio.async_server
Python Library Documentation: module socketio.async_server in socketio
NAME
socketio.async_server
CLASSES
socketio.base_server.BaseServer(builtins.object)
AsyncServer
class AsyncServer(socketio.base_server.BaseServer)
| AsyncServer(client_manager=None, logger=False, json=None, async_handlers=True, namespaces=None, **kwargs)
|
| A Socket.IO server for asyncio.
|
| This class implements a fully compliant Socket.IO web server with support
| for websocket and long-polling transports, compatible with the asyncio
| framework.
|
| :param client_manager: The client manager instance that will manage the
| client list. When this is omitted, the client list
| is stored in an in-memory structure, so the use of
| multiple connected servers is not possible.
| :param logger: To enable logging set to ``True`` or pass a logger object to
| use. To disable logging set to ``False``. Note that fatal
| errors are logged even when ``logger`` is ``False``.
| :param json: An alternative JSON module to use for encoding and decoding
| packets. Custom json modules must have ``dumps`` and ``loads``
| functions that are compatible with the standard library
| versions. This is a process-wide setting, all instantiated
| servers and clients must use the same JSON module.
| :param async_handlers: If set to ``True``, event handlers for a client are
| executed in separate threads. To run handlers for a
| client synchronously, set to ``False``. The default
| is ``True``.
| :param always_connect: When set to ``False``, new connections are
| provisory until the connect handler returns
| something other than ``False``, at which point they
| are accepted. When set to ``True``, connections are
| immediately accepted, and then if the connect
| handler returns ``False`` a disconnect is issued.
| Set to ``True`` if you need to emit events from the
| connect handler and your client is confused when it
| receives events before the connection acceptance.
| In any other case use the default of ``False``.
| :param namespaces: a list of namespaces that are accepted, in addition to
| any namespaces for which handlers have been defined. The
| default is `['/']`, which always accepts connections to
| the default namespace. Set to `'*'` to accept all
| namespaces.
| :param kwargs: Connection parameters for the underlying Engine.IO server.
|
| The Engine.IO configuration supports the following settings:
|
| :param async_mode: The asynchronous model to use. See the Deployment
| section in the documentation for a description of the
| available options. Valid async modes are "aiohttp",
| "sanic", "tornado" and "asgi". If this argument is not
| given, "aiohttp" is tried first, followed by "sanic",
| "tornado", and finally "asgi". The first async mode that
| has all its dependencies installed is the one that is
| chosen.
| :param ping_interval: The interval in seconds at which the server pings
| the client. The default is 25 seconds. For advanced
| control, a two element tuple can be given, where
| the first number is the ping interval and the second
| is a grace period added by the server.
| :param ping_timeout: The time in seconds that the client waits for the
| server to respond before disconnecting. The default
| is 20 seconds.
| :param max_http_buffer_size: The maximum size that is accepted for incoming
| messages. The default is 1,000,000 bytes. In
| spite of its name, the value set in this
| argument is enforced for HTTP long-polling and
| WebSocket connections.
| :param allow_upgrades: Whether to allow transport upgrades or not. The
| default is ``True``.
| :param http_compression: Whether to compress packages when using the
| polling transport. The default is ``True``.
| :param compression_threshold: Only compress messages when their byte size
| is greater than this value. The default is
| 1024 bytes.
| :param cookie: If set to a string, it is the name of the HTTP cookie the
| server sends back to the client containing the client
| session id. If set to a dictionary, the ``'name'`` key
| contains the cookie name and other keys define cookie
| attributes, where the value of each attribute can be a
| string, a callable with no arguments, or a boolean. If set
| to ``None`` (the default), a cookie is not sent to the
| client.
| :param cors_allowed_origins: Origin or list of origins that are allowed to
| connect to this server. Only the same origin
| is allowed by default. Set this argument to
| ``'*'`` to allow all origins, or to ``[]`` to
| disable CORS handling.
| :param cors_credentials: Whether credentials (cookies, authentication) are
| allowed in requests to this server. The default is
| ``True``.
| :param monitor_clients: If set to ``True``, a background task will ensure
| inactive clients are closed. Set to ``False`` to
| disable the monitoring task (not recommended). The
| default is ``True``.
| :param transports: The list of allowed transports. Valid transports
| are ``'polling'`` and ``'websocket'``. Defaults to
| ``['polling', 'websocket']``.
| :param engineio_logger: To enable Engine.IO logging set to ``True`` or pass
| a logger object to use. To disable logging set to
| ``False``. The default is ``False``. Note that
| fatal errors are logged even when
| ``engineio_logger`` is ``False``.
|
| Method resolution order:
| AsyncServer
| socketio.base_server.BaseServer
| builtins.object
|
| Methods defined here:
|
| __init__(self, client_manager=None, logger=False, json=None, async_handlers=True, namespaces=None, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| attach(self, app, socketio_path='socket.io')
| Attach the Socket.IO server to an application.
|
| async call(self, event, data=None, to=None, sid=None, namespace=None, timeout=60, ignore_queue=False)
| Emit a custom event to a client and wait for the response.
|
| This method issues an emit with a callback and waits for the callback
| to be invoked before returning. If the callback isn't invoked before
| the timeout, then a ``TimeoutError`` exception is raised. If the
| Socket.IO connection drops during the wait, this method still waits
| until the specified timeout.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used.
| :param data: The data to send to the client or clients. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
| :param to: The session ID of the recipient client.
| :param sid: Alias for the ``to`` parameter.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the event is emitted to the
| default namespace.
| :param timeout: The waiting timeout. If the timeout is reached before
| the client acknowledges the event, then a
| ``TimeoutError`` exception is raised.
| :param ignore_queue: Only used when a message queue is configured. If
| set to ``True``, the event is emitted to the
| client directly, without going through the queue.
| This is more efficient, but only works when a
| single server process is used. It is recommended
| to always leave this parameter with its default
| value of ``False``.
|
| Note: this method is not designed to be used concurrently. If multiple
| tasks are emitting at the same time to the same client connection, then
| messages composed of multiple packets may end up being sent in an
| incorrect sequence. Use standard concurrency solutions (such as a Lock
| object) to prevent this situation.
|
| Note 2: this method is a coroutine.
|
| async close_room(self, room, namespace=None)
| Close a room.
|
| This function removes all the clients from the given room.
|
| :param room: Room name.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the default namespace is used.
|
| Note: this method is a coroutine.
|
| async disconnect(self, sid, namespace=None, ignore_queue=False)
| Disconnect a client.
|
| :param sid: Session ID of the client.
| :param namespace: The Socket.IO namespace to disconnect. If this
| argument is omitted the default namespace is used.
| :param ignore_queue: Only used when a message queue is configured. If
| set to ``True``, the disconnect is processed
| locally, without broadcasting on the queue. It is
| recommended to always leave this parameter with
| its default value of ``False``.
|
| Note: this method is a coroutine.
|
| async emit(self, event, data=None, to=None, room=None, skip_sid=None, namespace=None, callback=None, ignore_queue=False)
| Emit a custom event to one or more connected clients.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used.
| :param data: The data to send to the client or clients. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
| :param to: The recipient of the message. This can be set to the
| session ID of a client to address only that client, to any
| any custom room created by the application to address all
| the clients in that room, or to a list of custom room
| names. If this argument is omitted the event is broadcasted
| to all connected clients.
| :param room: Alias for the ``to`` parameter.
| :param skip_sid: The session ID of a client to skip when broadcasting
| to a room or to all clients. This can be used to
| prevent a message from being sent to the sender.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the event is emitted to the
| default namespace.
| :param callback: If given, this function will be called to acknowledge
| the client has received the message. The arguments
| that will be passed to the function are those provided
| by the client. Callback functions can only be used
| when addressing an individual client.
| :param ignore_queue: Only used when a message queue is configured. If
| set to ``True``, the event is emitted to the
| clients directly, without going through the queue.
| This is more efficient, but only works when a
| single server process is used. It is recommended
| to always leave this parameter with its default
| value of ``False``.
|
| Note: this method is not designed to be used concurrently. If multiple
| tasks are emitting at the same time to the same client connection, then
| messages composed of multiple packets may end up being sent in an
| incorrect sequence. Use standard concurrency solutions (such as a Lock
| object) to prevent this situation.
|
| Note 2: this method is a coroutine.
|
| async enter_room(self, sid, room, namespace=None)
| Enter a room.
|
| This function adds the client to a room. The :func:`emit` and
| :func:`send` functions can optionally broadcast events to all the
| clients in a room.
|
| :param sid: Session ID of the client.
| :param room: Room name. If the room does not exist it is created.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the default namespace is used.
|
| Note: this method is a coroutine.
|
| async get_session(self, sid, namespace=None)
| Return the user session for a client.
|
| :param sid: The session id of the client.
| :param namespace: The Socket.IO namespace. If this argument is omitted
| the default namespace is used.
|
| The return value is a dictionary. Modifications made to this
| dictionary are not guaranteed to be preserved. If you want to modify
| the user session, use the ``session`` context manager instead.
|
| async handle_request(self, *args, **kwargs)
| Handle an HTTP request from the client.
|
| This is the entry point of the Socket.IO application. This function
| returns the HTTP response body to deliver to the client.
|
| Note: this method is a coroutine.
|
| instrument(self, auth=None, mode='development', read_only=False, server_id=None, namespace='/admin', server_stats_interval=2)
| Instrument the Socket.IO server for monitoring with the `Socket.IO
| Admin UI <https://socket.io/docs/v4/admin-ui/>`_.
|
| :param auth: Authentication credentials for Admin UI access. Set to a
| dictionary with the expected login (usually ``username``
| and ``password``) or a list of dictionaries if more than
| one set of credentials need to be available. For more
| complex authentication methods, set to a callable that
| receives the authentication dictionary as an argument and
| returns ``True`` if the user is allowed or ``False``
| otherwise. To disable authentication, set this argument to
| ``False`` (not recommended, never do this on a production
| server).
| :param mode: The reporting mode. The default is ``'development'``,
| which is best used while debugging, as it may have a
| significant performance effect. Set to ``'production'`` to
| reduce the amount of information that is reported to the
| admin UI.
| :param read_only: If set to ``True``, the admin interface will be
| read-only, with no option to modify room assignments
| or disconnect clients. The default is ``False``.
| :param server_id: The server name to use for this server. If this
| argument is omitted, the server generates its own
| name.
| :param namespace: The Socket.IO namespace to use for the admin
| interface. The default is ``/admin``.
| :param server_stats_interval: The interval in seconds at which the
| server emits a summary of it stats to all
| connected admins.
|
| is_asyncio_based(self)
|
| async leave_room(self, sid, room, namespace=None)
| Leave a room.
|
| This function removes the client from a room.
|
| :param sid: Session ID of the client.
| :param room: Room name.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the default namespace is used.
|
| Note: this method is a coroutine.
|
| async save_session(self, sid, session, namespace=None)
| Store the user session for a client.
|
| :param sid: The session id of the client.
| :param session: The session dictionary.
| :param namespace: The Socket.IO namespace. If this argument is omitted
| the default namespace is used.
|
| async send(self, data, to=None, room=None, skip_sid=None, namespace=None, callback=None, ignore_queue=False)
| Send a message to one or more connected clients.
|
| This function emits an event with the name ``'message'``. Use
| :func:`emit` to issue custom event names.
|
| :param data: The data to send to the client or clients. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
| :param to: The recipient of the message. This can be set to the
| session ID of a client to address only that client, to any
| any custom room created by the application to address all
| the clients in that room, or to a list of custom room
| names. If this argument is omitted the event is broadcasted
| to all connected clients.
| :param room: Alias for the ``to`` parameter.
| :param skip_sid: The session ID of a client to skip when broadcasting
| to a room or to all clients. This can be used to
| prevent a message from being sent to the sender.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the event is emitted to the
| default namespace.
| :param callback: If given, this function will be called to acknowledge
| the client has received the message. The arguments
| that will be passed to the function are those provided
| by the client. Callback functions can only be used
| when addressing an individual client.
| :param ignore_queue: Only used when a message queue is configured. If
| set to ``True``, the event is emitted to the
| clients directly, without going through the queue.
| This is more efficient, but only works when a
| single server process is used. It is recommended
| to always leave this parameter with its default
| value of ``False``.
|
| Note: this method is a coroutine.
|
| session(self, sid, namespace=None)
| Return the user session for a client with context manager syntax.
|
| :param sid: The session id of the client.
|
| This is a context manager that returns the user session dictionary for
| the client. Any changes that are made to this dictionary inside the
| context manager block are saved back to the session. Example usage::
|
| @eio.on('connect')
| async def on_connect(sid, environ):
| username = authenticate_user(environ)
| if not username:
| return False
| async with eio.session(sid) as session:
| session['username'] = username
|
| @eio.on('message')
| async def on_message(sid, msg):
| async with eio.session(sid) as session:
| print('received message from ', session['username'])
|
| async shutdown(self)
| Stop Socket.IO background tasks.
|
| This method stops all background activity initiated by the Socket.IO
| server. It must be called before shutting down the web server.
|
| async sleep(self, seconds=0)
| Sleep for the requested amount of time using the appropriate async
| model.
|
| This is a utility function that applications can use to put a task to
| sleep without having to worry about using the correct call for the
| selected async mode.
|
| Note: this method is a coroutine.
|
| start_background_task(self, target, *args, **kwargs)
| Start a background task using the appropriate async model.
|
| This is a utility function that applications can use to start a
| background task using the method that is compatible with the
| selected async mode.
|
| :param target: the target function to execute. Must be a coroutine.
| :param args: arguments to pass to the function.
| :param kwargs: keyword arguments to pass to the function.
|
| The return value is a ``asyncio.Task`` object.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.base_server.BaseServer:
|
| event(self, *args, **kwargs)
| Decorator to register an event handler.
|
| This is a simplified version of the ``on()`` method that takes the
| event name from the decorated function.
|
| Example usage::
|
| @sio.event
| def my_event(data):
| print('Received data: ', data)
|
| The above example is equivalent to::
|
| @sio.on('my_event')
| def my_event(data):
| print('Received data: ', data)
|
| A custom namespace can be given as an argument to the decorator::
|
| @sio.event(namespace='/test')
| def my_event(data):
| print('Received data: ', data)
|
| get_environ(self, sid, namespace=None)
| Return the WSGI environ dictionary for a client.
|
| :param sid: The session of the client.
| :param namespace: The Socket.IO namespace. If this argument is omitted
| the default namespace is used.
|
| on(self, event, handler=None, namespace=None)
| Register an event handler.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used. The ``'*'`` event name
| can be used to define a catch-all event handler.
| :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. A catch-all namespace can be
| defined by passing ``'*'`` as the namespace.
|
| Example usage::
|
| # as a decorator:
| @sio.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)
| sio.send(sid, 'response')
| socket_io.on('message', namespace='/chat', handler=message_handler)
|
| The arguments passed to the handler function depend on the event type:
|
| - The ``'connect'`` event handler receives the ``sid`` (session ID) for
| the client and the WSGI environment dictionary as arguments.
| - The ``'disconnect'`` handler receives the ``sid`` for the client as
| only argument.
| - The ``'message'`` handler and handlers for custom event names receive
| the ``sid`` for the client and the message payload as arguments. Any
| values returned from a message handler will be passed to the client's
| acknowledgement callback function if it exists.
| - A catch-all event handler receives the event name as first argument,
| followed by any arguments specific to the event.
| - A catch-all namespace event handler receives the namespace as first
| argument, followed by any arguments specific to the event.
| - A combined catch-all namespace and catch-all event handler receives
| the event name as first argument and the namespace as second
| argument, followed by any arguments specific to the event.
|
| register_namespace(self, namespace_handler)
| Register a namespace handler object.
|
| :param namespace_handler: An instance of a :class:`Namespace`
| subclass that handles all the event traffic
| for a namespace.
|
| rooms(self, sid, namespace=None)
| Return the rooms a client is in.
|
| :param sid: Session ID of the client.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the default namespace is used.
|
| transport(self, sid, namespace=None)
| Return the name of the transport used by the client.
|
| The two possible values returned by this function are ``'polling'``
| and ``'websocket'``.
|
| :param sid: The session of the client.
| :param namespace: The Socket.IO namespace. If this argument is omitted
| the default namespace is used.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketio.base_server.BaseServer:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketio.base_server.BaseServer:
|
| reason = <class 'engineio.base_server.BaseServer.reason'>
| Disconnection reasons.
|
|
| reserved_events = ['connect', 'disconnect']
DATA
task_reference_holder = set()
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\socketio\async_server.py
socketio.async_simple_client
Python Library Documentation: module socketio.async_simple_client in socketio
NAME
socketio.async_simple_client
CLASSES
builtins.object
AsyncSimpleClient
class AsyncSimpleClient(builtins.object)
| AsyncSimpleClient(*args, **kwargs)
|
| A Socket.IO client.
|
| This class implements a simple, yet fully compliant Socket.IO web client
| with support for websocket and long-polling transports.
|
| The positional and keyword arguments given in the constructor are passed
| to the underlying :func:`socketio.AsyncClient` object.
|
| Methods defined here:
|
| async __aenter__(self)
|
| async __aexit__(self, exc_type, exc_val, exc_tb)
|
| __init__(self, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| async call(self, event, data=None, timeout=60)
| Emit an event to the server and wait for a response.
|
| This method issues an emit and waits for the server to provide a
| response or acknowledgement. If the response does not arrive before the
| timeout, then a ``TimeoutError`` exception is raised.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used.
| :param data: The data to send to the server. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
| :param timeout: The waiting timeout. If the timeout is reached before
| the server acknowledges the event, then a
| ``TimeoutError`` exception is raised.
|
| Note: this method is a coroutine.
|
| async connect(self, url, headers={}, auth=None, transports=None, namespace='/', socketio_path='socket.io', wait_timeout=5)
| Connect to a Socket.IO server.
|
| :param url: The URL of the Socket.IO server. It can include custom
| query string parameters if required by the server. If a
| function is provided, the client will invoke it to obtain
| the URL each time a connection or reconnection is
| attempted.
| :param headers: A dictionary with custom headers to send with the
| connection request. If a function is provided, the
| client will invoke it to obtain the headers dictionary
| each time a connection or reconnection is attempted.
| :param auth: Authentication data passed to the server with the
| connection request, normally a dictionary with one or
| more string key/value pairs. If a function is provided,
| the client will invoke it to obtain the authentication
| data each time a connection or reconnection is attempted.
| :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 namespace: The namespace to connect to as a string. If not
| given, the default namespace ``/`` is used.
| :param socketio_path: The endpoint where the Socket.IO server is
| installed. The default value is appropriate for
| most cases.
| :param wait_timeout: How long the client should wait for the
| connection. The default is 5 seconds.
|
| Note: this method is a coroutine.
|
| async disconnect(self)
| Disconnect from the server.
|
| Note: this method is a coroutine.
|
| async emit(self, event, data=None)
| Emit an event to the server.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used.
| :param data: The data to send to the server. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
|
| Note: this method is a coroutine.
|
| This method schedules the event to be sent out and returns, without
| actually waiting for its delivery. In cases where the client needs to
| ensure that the event was received, :func:`socketio.SimpleClient.call`
| should be used instead.
|
| async receive(self, timeout=None)
| Wait for an event from the server.
|
| :param timeout: The waiting timeout. If the timeout is reached before
| the server acknowledges the event, then a
| ``TimeoutError`` exception is raised.
|
| Note: this method is a coroutine.
|
| The return value is a list with the event name as the first element. If
| the server included arguments with the event, they are returned as
| additional list elements.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| sid
| The session ID received from the server.
|
| The session ID is not guaranteed to remain constant throughout the life
| of the connection, as reconnections can cause it to change.
|
| transport
| The name of the transport currently in use.
|
| The transport is returned as a string and can be one of ``polling``
| and ``websocket``.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| client_class = <class 'socketio.async_client.AsyncClient'>
| A Socket.IO client for asyncio.
|
| This class implements a fully compliant Socket.IO web client with support
| for websocket and long-polling transports.
|
| :param reconnection: ``True`` if the client should automatically attempt to
| reconnect to the server after an interruption, or
| ``False`` to not reconnect. The default is ``True``.
| :param reconnection_attempts: How many reconnection attempts to issue
| before giving up, or 0 for infinite attempts.
| The default is 0.
| :param reconnection_delay: How long to wait in seconds before the first
| reconnection attempt. Each successive attempt
| doubles this delay.
| :param reconnection_delay_max: The maximum delay between reconnection
| attempts.
| :param randomization_factor: Randomization amount for each delay between
| reconnection attempts. The default is 0.5,
| which means that each delay is randomly
| adjusted by +/- 50%.
| :param logger: To enable logging set to ``True`` or pass a logger object to
| use. To disable logging set to ``False``. The default is
| ``False``. Note that fatal errors are logged even when
| ``logger`` is ``False``.
| :param json: An alternative JSON module to use for encoding and decoding
| packets. Custom json modules must have ``dumps`` and ``loads``
| functions that are compatible with the standard library
| versions. This is a process-wide setting, all instantiated
| servers and clients must use the same JSON module.
| :param handle_sigint: Set to ``True`` to automatically handle disconnection
| when the process is interrupted, or to ``False`` to
| leave interrupt handling to the calling application.
| Interrupt handling can only be enabled when the
| client instance is created in the main thread.
|
| The Engine.IO configuration supports the following settings:
|
| :param request_timeout: A timeout in seconds for requests. The default is
| 5 seconds.
| :param http_session: an initialized ``aiohttp.ClientSession`` object to be
| used when sending requests to the server. Use it if
| you need to add special client options such as proxy
| servers, SSL certificates, custom CA bundle, etc.
| :param ssl_verify: ``True`` to verify SSL certificates, or ``False`` to
| skip SSL certificate verification, allowing
| connections to servers with self signed certificates.
| The default is ``True``.
| :param websocket_extra_options: Dictionary containing additional keyword
| arguments passed to
| ``websocket.create_connection()``.
| :param engineio_logger: To enable Engine.IO logging set to ``True`` or pass
| a logger object to use. To disable logging set to
| ``False``. The default is ``False``. Note that
| fatal errors are logged even when
| ``engineio_logger`` is ``False``.
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\socketio\async_simple_client.py
socketio.base_client
Python Library Documentation: module socketio.base_client in socketio
NAME
socketio.base_client
CLASSES
builtins.object
BaseClient
class BaseClient(builtins.object)
| BaseClient(reconnection=True, reconnection_attempts=0, reconnection_delay=1, reconnection_delay_max=5, randomization_factor=0.5, logger=False, serializer='default', json=None, handle_sigint=True, **kwargs)
|
| Methods defined here:
|
| __init__(self, reconnection=True, reconnection_attempts=0, reconnection_delay=1, reconnection_delay_max=5, randomization_factor=0.5, logger=False, serializer='default', json=None, handle_sigint=True, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| event(self, *args, **kwargs)
| Decorator to register an event handler.
|
| This is a simplified version of the ``on()`` method that takes the
| event name from the decorated function.
|
| Example usage::
|
| @sio.event
| def my_event(data):
| print('Received data: ', data)
|
| The above example is equivalent to::
|
| @sio.on('my_event')
| def my_event(data):
| print('Received data: ', data)
|
| A custom namespace can be given as an argument to the decorator::
|
| @sio.event(namespace='/test')
| def my_event(data):
| print('Received data: ', data)
|
| get_sid(self, namespace=None)
| Return the ``sid`` associated with a connection.
|
| :param namespace: The Socket.IO namespace. If this argument is omitted
| the handler is associated with the default
| namespace. Note that unlike previous versions, the
| current version of the Socket.IO protocol uses
| different ``sid`` values per namespace.
|
| This method returns the ``sid`` for the requested namespace as a
| string.
|
| is_asyncio_based(self)
|
| on(self, event, handler=None, namespace=None)
| Register an event handler.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used. The ``'*'`` event name
| can be used to define a catch-all event handler.
| :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. A catch-all namespace can be
| defined by passing ``'*'`` as the namespace.
|
| Example usage::
|
| # as a decorator:
| @sio.on('connect')
| def connect_handler():
| print('Connected!')
|
| # as a method:
| def message_handler(msg):
| print('Received message: ', msg)
| sio.send( 'response')
| sio.on('message', message_handler)
|
| The arguments passed to the handler function depend on the event type:
|
| - The ``'connect'`` event handler does not take arguments.
| - The ``'disconnect'`` event handler does not take arguments.
| - The ``'message'`` handler and handlers for custom event names receive
| the message payload as only argument. Any values returned from a
| message handler will be passed to the client's acknowledgement
| callback function if it exists.
| - A catch-all event handler receives the event name as first argument,
| followed by any arguments specific to the event.
| - A catch-all namespace event handler receives the namespace as first
| argument, followed by any arguments specific to the event.
| - A combined catch-all namespace and catch-all event handler receives
| the event name as first argument and the namespace as second
| argument, followed by any arguments specific to the event.
|
| register_namespace(self, namespace_handler)
| Register a namespace handler object.
|
| :param namespace_handler: An instance of a :class:`Namespace`
| subclass that handles all the event traffic
| for a namespace.
|
| transport(self)
| Return the name of the transport used by the client.
|
| The two possible values returned by this function are ``'polling'``
| and ``'websocket'``.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| reason = <class 'engineio.base_client.BaseClient.reason'>
| Disconnection reasons.
|
|
| reserved_events = ['connect', 'connect_error', 'disconnect', '__discon...
FUNCTIONS
signal_handler(sig, frame)
SIGINT handler.
Notify any clients that are in a reconnect loop to abort. Other
disconnection tasks are handled at the engine.io level.
DATA
default_logger = <Logger socketio.client (WARNING)>
original_signal_handler = None
reconnecting_clients = []
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\socketio\base_client.py
socketio.base_manager
Python Library Documentation: module socketio.base_manager in socketio
NAME
socketio.base_manager
CLASSES
builtins.object
BaseManager
class BaseManager(builtins.object)
| Methods defined here:
|
| __init__(self)
| Initialize self. See help(type(self)) for accurate signature.
|
| basic_close_room(self, room, namespace)
|
| basic_disconnect(self, sid, namespace, **kwargs)
|
| basic_enter_room(self, sid, namespace, room, eio_sid=None)
|
| basic_leave_room(self, sid, namespace, room)
|
| connect(self, eio_sid, namespace)
| Register a client connection to a namespace.
|
| eio_sid_from_sid(self, sid, namespace)
|
| get_namespaces(self)
| Return an iterable with the active namespace names.
|
| get_participants(self, namespace, room)
| Return an iterable with the active participants in a room.
|
| Note that in a multi-server scenario this method only returns the
| participants connect to the server in which the method is called. There
| is currently no functionality to assemble a complete list of users
| across multiple servers.
|
| get_rooms(self, sid, namespace)
| Return the rooms a client is in.
|
| initialize(self)
| Invoked before the first request is received. Subclasses can add
| their initialization code here.
|
| is_connected(self, sid, namespace)
|
| pre_disconnect(self, sid, namespace)
| Put the client in the to-be-disconnected list.
|
| This allows the client data structures to be present while the
| disconnect handler is invoked, but still recognize the fact that the
| client is soon going away.
|
| set_server(self, server)
|
| sid_from_eio_sid(self, eio_sid, namespace)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
DATA
default_logger = <Logger socketio (WARNING)>
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\socketio\base_manager.py
socketio.base_namespace
Python Library Documentation: module socketio.base_namespace in socketio
NAME
socketio.base_namespace
CLASSES
builtins.object
BaseNamespace
BaseClientNamespace
BaseServerNamespace
class BaseClientNamespace(BaseNamespace)
| BaseClientNamespace(namespace=None)
|
| Method resolution order:
| BaseClientNamespace
| BaseNamespace
| builtins.object
|
| Methods defined here:
|
| __init__(self, namespace=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseNamespace:
|
| is_asyncio_based(self)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseNamespace:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class BaseNamespace(builtins.object)
| BaseNamespace(namespace=None)
|
| Methods defined here:
|
| __init__(self, namespace=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| is_asyncio_based(self)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class BaseServerNamespace(BaseNamespace)
| BaseServerNamespace(namespace=None)
|
| Method resolution order:
| BaseServerNamespace
| BaseNamespace
| builtins.object
|
| Methods defined here:
|
| __init__(self, namespace=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| rooms(self, sid, namespace=None)
| Return the rooms a client is in.
|
| The only difference with the :func:`socketio.Server.rooms` method is
| that when the ``namespace`` argument is not given the namespace
| associated with the class is used.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseNamespace:
|
| is_asyncio_based(self)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseNamespace:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\socketio\base_namespace.py
socketio.base_server
Python Library Documentation: module socketio.base_server in socketio
NAME
socketio.base_server
CLASSES
builtins.object
BaseServer
class BaseServer(builtins.object)
| BaseServer(client_manager=None, logger=False, serializer='default', json=None, async_handlers=True, always_connect=False, namespaces=None, **kwargs)
|
| Methods defined here:
|
| __init__(self, client_manager=None, logger=False, serializer='default', json=None, async_handlers=True, always_connect=False, namespaces=None, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| event(self, *args, **kwargs)
| Decorator to register an event handler.
|
| This is a simplified version of the ``on()`` method that takes the
| event name from the decorated function.
|
| Example usage::
|
| @sio.event
| def my_event(data):
| print('Received data: ', data)
|
| The above example is equivalent to::
|
| @sio.on('my_event')
| def my_event(data):
| print('Received data: ', data)
|
| A custom namespace can be given as an argument to the decorator::
|
| @sio.event(namespace='/test')
| def my_event(data):
| print('Received data: ', data)
|
| get_environ(self, sid, namespace=None)
| Return the WSGI environ dictionary for a client.
|
| :param sid: The session of the client.
| :param namespace: The Socket.IO namespace. If this argument is omitted
| the default namespace is used.
|
| is_asyncio_based(self)
|
| on(self, event, handler=None, namespace=None)
| Register an event handler.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used. The ``'*'`` event name
| can be used to define a catch-all event handler.
| :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. A catch-all namespace can be
| defined by passing ``'*'`` as the namespace.
|
| Example usage::
|
| # as a decorator:
| @sio.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)
| sio.send(sid, 'response')
| socket_io.on('message', namespace='/chat', handler=message_handler)
|
| The arguments passed to the handler function depend on the event type:
|
| - The ``'connect'`` event handler receives the ``sid`` (session ID) for
| the client and the WSGI environment dictionary as arguments.
| - The ``'disconnect'`` handler receives the ``sid`` for the client as
| only argument.
| - The ``'message'`` handler and handlers for custom event names receive
| the ``sid`` for the client and the message payload as arguments. Any
| values returned from a message handler will be passed to the client's
| acknowledgement callback function if it exists.
| - A catch-all event handler receives the event name as first argument,
| followed by any arguments specific to the event.
| - A catch-all namespace event handler receives the namespace as first
| argument, followed by any arguments specific to the event.
| - A combined catch-all namespace and catch-all event handler receives
| the event name as first argument and the namespace as second
| argument, followed by any arguments specific to the event.
|
| register_namespace(self, namespace_handler)
| Register a namespace handler object.
|
| :param namespace_handler: An instance of a :class:`Namespace`
| subclass that handles all the event traffic
| for a namespace.
|
| rooms(self, sid, namespace=None)
| Return the rooms a client is in.
|
| :param sid: Session ID of the client.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the default namespace is used.
|
| transport(self, sid, namespace=None)
| Return the name of the transport used by the client.
|
| The two possible values returned by this function are ``'polling'``
| and ``'websocket'``.
|
| :param sid: The session of the client.
| :param namespace: The Socket.IO namespace. If this argument is omitted
| the default namespace is used.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| reason = <class 'engineio.base_server.BaseServer.reason'>
| Disconnection reasons.
|
|
| reserved_events = ['connect', 'disconnect']
DATA
default_logger = <Logger socketio.server (WARNING)>
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\socketio\base_server.py
socketio.client
Python Library Documentation: module socketio.client in socketio
NAME
socketio.client
CLASSES
socketio.base_client.BaseClient(builtins.object)
Client
class Client(socketio.base_client.BaseClient)
| Client(reconnection=True, reconnection_attempts=0, reconnection_delay=1, reconnection_delay_max=5, randomization_factor=0.5, logger=False, serializer='default', json=None, handle_sigint=True, **kwargs)
|
| A Socket.IO client.
|
| This class implements a fully compliant Socket.IO web client with support
| for websocket and long-polling transports.
|
| :param reconnection: ``True`` if the client should automatically attempt to
| reconnect to the server after an interruption, or
| ``False`` to not reconnect. The default is ``True``.
| :param reconnection_attempts: How many reconnection attempts to issue
| before giving up, or 0 for infinite attempts.
| The default is 0.
| :param reconnection_delay: How long to wait in seconds before the first
| reconnection attempt. Each successive attempt
| doubles this delay.
| :param reconnection_delay_max: The maximum delay between reconnection
| attempts.
| :param randomization_factor: Randomization amount for each delay between
| reconnection attempts. The default is 0.5,
| which means that each delay is randomly
| adjusted by +/- 50%.
| :param logger: To enable logging set to ``True`` or pass a logger object to
| use. To disable logging set to ``False``. The default is
| ``False``. Note that fatal errors are logged even when
| ``logger`` is ``False``.
| :param serializer: The serialization method to use when transmitting
| packets. Valid values are ``'default'``, ``'pickle'``,
| ``'msgpack'`` and ``'cbor'``. Alternatively, a subclass
| of the :class:`Packet` class with custom implementations
| of the ``encode()`` and ``decode()`` methods can be
| provided. Client and server must use compatible
| serializers.
| :param json: An alternative JSON module to use for encoding and decoding
| packets. Custom json modules must have ``dumps`` and ``loads``
| functions that are compatible with the standard library
| versions. This is a process-wide setting, all instantiated
| servers and clients must use the same JSON module.
| :param handle_sigint: Set to ``True`` to automatically handle disconnection
| when the process is interrupted, or to ``False`` to
| leave interrupt handling to the calling application.
| Interrupt handling can only be enabled when the
| client instance is created in the main thread.
|
| The Engine.IO configuration supports the following settings:
|
| :param request_timeout: A timeout in seconds for requests. The default is
| 5 seconds.
| :param http_session: an initialized ``requests.Session`` object to be used
| when sending requests to the server. Use it if you
| need to add special client options such as proxy
| servers, SSL certificates, custom CA bundle, etc.
| :param ssl_verify: ``True`` to verify SSL certificates, or ``False`` to
| skip SSL certificate verification, allowing
| connections to servers with self signed certificates.
| The default is ``True``.
| :param websocket_extra_options: Dictionary containing additional keyword
| arguments passed to
| ``websocket.create_connection()``.
| :param engineio_logger: To enable Engine.IO logging set to ``True`` or pass
| a logger object to use. To disable logging set to
| ``False``. The default is ``False``. Note that
| fatal errors are logged even when
| ``engineio_logger`` is ``False``.
|
| Method resolution order:
| Client
| socketio.base_client.BaseClient
| builtins.object
|
| Methods defined here:
|
| call(self, event, data=None, namespace=None, timeout=60)
| Emit a custom event to the server and wait for the response.
|
| This method issues an emit with a callback and waits for the callback
| to be invoked before returning. If the callback isn't invoked before
| the timeout, then a ``TimeoutError`` exception is raised. If the
| Socket.IO connection drops during the wait, this method still waits
| until the specified timeout.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used.
| :param data: The data to send to the server. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the event is emitted to the
| default namespace.
| :param timeout: The waiting timeout. If the timeout is reached before
| the server acknowledges the event, then a
| ``TimeoutError`` exception is raised.
|
| Note: this method is not thread safe. If multiple threads are emitting
| at the same time on the same client connection, messages composed of
| multiple packets may end up being sent in an incorrect sequence. Use
| standard concurrency solutions (such as a Lock object) to prevent this
| situation.
|
| connect(self, url, headers={}, auth=None, transports=None, namespaces=None, socketio_path='socket.io', wait=True, wait_timeout=1, retry=False)
| Connect to a Socket.IO server.
|
| :param url: The URL of the Socket.IO server. It can include custom
| query string parameters if required by the server. If a
| function is provided, the client will invoke it to obtain
| the URL each time a connection or reconnection is
| attempted.
| :param headers: A dictionary with custom headers to send with the
| connection request. If a function is provided, the
| client will invoke it to obtain the headers dictionary
| each time a connection or reconnection is attempted.
| :param auth: Authentication data passed to the server with the
| connection request, normally a dictionary with one or
| more string key/value pairs. If a function is provided,
| the client will invoke it to obtain the authentication
| data each time a connection or reconnection is attempted.
| :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.
| :param wait: if set to ``True`` (the default) the call only returns
| when all the namespaces are connected. If set to
| ``False``, the call returns as soon as the Engine.IO
| transport is connected, and the namespaces will connect
| in the background.
| :param wait_timeout: How long the client should wait for the
| connection. The default is 1 second. This
| argument is only considered when ``wait`` is set
| to ``True``.
| :param retry: Apply the reconnection logic if the initial connection
| attempt fails. The default is ``False``.
|
| Example usage::
|
| sio = socketio.Client()
| sio.connect('http://localhost:5000')
|
| disconnect(self)
| Disconnect from the server.
|
| emit(self, event, data=None, namespace=None, callback=None)
| Emit a custom event to the server.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used.
| :param data: The data to send to the server. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the event is emitted to the
| default namespace.
| :param callback: If given, this function will be called to acknowledge
| the server has received the message. The arguments
| that will be passed to the function are those provided
| by the server.
|
| Note: this method is not thread safe. If multiple threads are emitting
| at the same time on the same client connection, messages composed of
| multiple packets may end up being sent in an incorrect sequence. Use
| standard concurrency solutions (such as a Lock object) to prevent this
| situation.
|
| send(self, data, namespace=None, callback=None)
| Send a message to the server.
|
| This function emits an event with the name ``'message'``. Use
| :func:`emit` to issue custom event names.
|
| :param data: The data to send to the server. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the event is emitted to the
| default namespace.
| :param callback: If given, this function will be called to acknowledge
| the server has received the message. The arguments
| that will be passed to the function are those provided
| by the server.
|
| shutdown(self)
| Stop the client.
|
| If the client is connected to a server, it is disconnected. If the
| client is attempting to reconnect to server, the reconnection attempts
| are stopped. If the client is not connected to a server and is not
| attempting to reconnect, then this function does nothing.
|
| sleep(self, seconds=0)
| Sleep for the requested amount of time using the appropriate async
| model.
|
| This is a utility function that applications can use to put a task to
| sleep without having to worry about using the correct call for the
| selected async mode.
|
| start_background_task(self, target, *args, **kwargs)
| Start a background task using the appropriate async model.
|
| This is a utility function that applications can use to start a
| background task using the method that is compatible with the
| selected async mode.
|
| :param target: the target function to execute.
| :param args: arguments to pass to the function.
| :param kwargs: keyword arguments to pass to the function.
|
| This function returns an object that represents the background task,
| on which the ``join()`` methond can be invoked to wait for the task to
| complete.
|
| wait(self)
| Wait until the connection with the server ends.
|
| Client applications can use this function to block the main thread
| during the life of the connection.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.base_client.BaseClient:
|
| __init__(self, reconnection=True, reconnection_attempts=0, reconnection_delay=1, reconnection_delay_max=5, randomization_factor=0.5, logger=False, serializer='default', json=None, handle_sigint=True, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| event(self, *args, **kwargs)
| Decorator to register an event handler.
|
| This is a simplified version of the ``on()`` method that takes the
| event name from the decorated function.
|
| Example usage::
|
| @sio.event
| def my_event(data):
| print('Received data: ', data)
|
| The above example is equivalent to::
|
| @sio.on('my_event')
| def my_event(data):
| print('Received data: ', data)
|
| A custom namespace can be given as an argument to the decorator::
|
| @sio.event(namespace='/test')
| def my_event(data):
| print('Received data: ', data)
|
| get_sid(self, namespace=None)
| Return the ``sid`` associated with a connection.
|
| :param namespace: The Socket.IO namespace. If this argument is omitted
| the handler is associated with the default
| namespace. Note that unlike previous versions, the
| current version of the Socket.IO protocol uses
| different ``sid`` values per namespace.
|
| This method returns the ``sid`` for the requested namespace as a
| string.
|
| is_asyncio_based(self)
|
| on(self, event, handler=None, namespace=None)
| Register an event handler.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used. The ``'*'`` event name
| can be used to define a catch-all event handler.
| :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. A catch-all namespace can be
| defined by passing ``'*'`` as the namespace.
|
| Example usage::
|
| # as a decorator:
| @sio.on('connect')
| def connect_handler():
| print('Connected!')
|
| # as a method:
| def message_handler(msg):
| print('Received message: ', msg)
| sio.send( 'response')
| sio.on('message', message_handler)
|
| The arguments passed to the handler function depend on the event type:
|
| - The ``'connect'`` event handler does not take arguments.
| - The ``'disconnect'`` event handler does not take arguments.
| - The ``'message'`` handler and handlers for custom event names receive
| the message payload as only argument. Any values returned from a
| message handler will be passed to the client's acknowledgement
| callback function if it exists.
| - A catch-all event handler receives the event name as first argument,
| followed by any arguments specific to the event.
| - A catch-all namespace event handler receives the namespace as first
| argument, followed by any arguments specific to the event.
| - A combined catch-all namespace and catch-all event handler receives
| the event name as first argument and the namespace as second
| argument, followed by any arguments specific to the event.
|
| register_namespace(self, namespace_handler)
| Register a namespace handler object.
|
| :param namespace_handler: An instance of a :class:`Namespace`
| subclass that handles all the event traffic
| for a namespace.
|
| transport(self)
| Return the name of the transport used by the client.
|
| The two possible values returned by this function are ``'polling'``
| and ``'websocket'``.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketio.base_client.BaseClient:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketio.base_client.BaseClient:
|
| reason = <class 'engineio.base_client.BaseClient.reason'>
| Disconnection reasons.
|
|
| reserved_events = ['connect', 'connect_error', 'disconnect', '__discon...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\socketio\client.py
socketio.exceptions
Python Library Documentation: module socketio.exceptions in socketio
NAME
socketio.exceptions
CLASSES
builtins.Exception(builtins.BaseException)
SocketIOError
BadNamespaceError
ConnectionError
ConnectionRefusedError
DisconnectedError
TimeoutError
class BadNamespaceError(SocketIOError)
| Method resolution order:
| BadNamespaceError
| SocketIOError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors inherited from SocketIOError:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.Exception:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class ConnectionError(SocketIOError)
| Method resolution order:
| ConnectionError
| SocketIOError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors inherited from SocketIOError:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.Exception:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class ConnectionRefusedError(ConnectionError)
| ConnectionRefusedError(*args)
|
| Connection refused exception.
|
| This exception can be raised from a connect handler when the connection
| is not accepted. The positional arguments provided with the exception are
| returned with the error packet to the client.
|
| Method resolution order:
| ConnectionRefusedError
| ConnectionError
| SocketIOError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Methods defined here:
|
| __init__(self, *args)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from SocketIOError:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class DisconnectedError(SocketIOError)
| Method resolution order:
| DisconnectedError
| SocketIOError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors inherited from SocketIOError:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.Exception:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class SocketIOError(builtins.Exception)
| Method resolution order:
| SocketIOError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors defined here:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.Exception:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class TimeoutError(SocketIOError)
| Method resolution order:
| TimeoutError
| SocketIOError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors inherited from SocketIOError:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.Exception:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\socketio\exceptions.py
socketio.get_tornado_handler
Python Library Documentation: function get_tornado_handler in module socketio.tornado get_tornado_handler(socketio_server)
socketio.kafka_manager
Python Library Documentation: module socketio.kafka_manager in socketio
NAME
socketio.kafka_manager
CLASSES
socketio.pubsub_manager.PubSubManager(socketio.manager.Manager)
KafkaManager
class KafkaManager(socketio.pubsub_manager.PubSubManager)
| KafkaManager(url='kafka://localhost:9092', channel='socketio', write_only=False, logger=None, json=None)
|
| Kafka based client manager.
|
| This class implements a Kafka backend for event sharing across multiple
| processes.
|
| To use a Kafka backend, initialize the :class:`Server` instance as
| follows::
|
| url = 'kafka://hostname:port'
| server = socketio.Server(client_manager=socketio.KafkaManager(url))
|
| :param url: The connection URL for the Kafka server. For a default Kafka
| store running on the same host, use ``kafka://``. For a highly
| available deployment of Kafka, pass a list with all the
| connection URLs available in your cluster.
| :param channel: The channel name (topic) on which the server sends and
| receives notifications. Must be the same in all the
| servers.
| :param write_only: If set to ``True``, only initialize to emit events. The
| default of ``False`` initializes the class for emitting
| and receiving. A write-only instance can be used
| independently of the server to emit to clients from an
| external process.
| :param logger: a custom logger to log it. If not given, the server logger
| is used.
| :param json: An alternative JSON module to use for encoding and decoding
| packets. Custom json modules must have ``dumps`` and ``loads``
| functions that are compatible with the standard library
| versions. This setting is only used when ``write_only`` is set
| to ``True``. Otherwise the JSON module configured in the
| server is used.
|
| Method resolution order:
| KafkaManager
| socketio.pubsub_manager.PubSubManager
| socketio.manager.Manager
| socketio.base_manager.BaseManager
| builtins.object
|
| Methods defined here:
|
| __init__(self, url='kafka://localhost:9092', channel='socketio', write_only=False, logger=None, json=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| name = 'kafka'
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.pubsub_manager.PubSubManager:
|
| can_disconnect(self, sid, namespace)
|
| close_room(self, room, namespace=None)
| Remove all participants from a room.
|
| disconnect(self, sid, namespace=None, **kwargs)
| Register a client disconnect from a namespace.
|
| emit(self, event, data, namespace=None, room=None, skip_sid=None, callback=None, to=None, **kwargs)
| Emit a message to a single client, a room, or all the clients
| connected to the namespace.
|
| This method takes care or propagating the message to all the servers
| that are connected through the message queue.
|
| The parameters are the same as in :meth:`.Server.emit`.
|
| enter_room(self, sid, namespace, room, eio_sid=None)
| Add a client to a room.
|
| initialize(self)
| Invoked before the first request is received. Subclasses can add
| their initialization code here.
|
| leave_room(self, sid, namespace, room)
| Remove a client from a room.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.manager.Manager:
|
| trigger_callback(self, sid, id, data)
| Invoke an application callback.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.base_manager.BaseManager:
|
| basic_close_room(self, room, namespace)
|
| basic_disconnect(self, sid, namespace, **kwargs)
|
| basic_enter_room(self, sid, namespace, room, eio_sid=None)
|
| basic_leave_room(self, sid, namespace, room)
|
| connect(self, eio_sid, namespace)
| Register a client connection to a namespace.
|
| eio_sid_from_sid(self, sid, namespace)
|
| get_namespaces(self)
| Return an iterable with the active namespace names.
|
| get_participants(self, namespace, room)
| Return an iterable with the active participants in a room.
|
| Note that in a multi-server scenario this method only returns the
| participants connect to the server in which the method is called. There
| is currently no functionality to assemble a complete list of users
| across multiple servers.
|
| get_rooms(self, sid, namespace)
| Return the rooms a client is in.
|
| is_connected(self, sid, namespace)
|
| pre_disconnect(self, sid, namespace)
| Put the client in the to-be-disconnected list.
|
| This allows the client data structures to be present while the
| disconnect handler is invoked, but still recognize the fact that the
| client is soon going away.
|
| set_server(self, server)
|
| sid_from_eio_sid(self, eio_sid, namespace)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketio.base_manager.BaseManager:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
DATA
kafka = None
logger = <Logger socketio (WARNING)>
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\socketio\kafka_manager.py
socketio.kombu_manager
Python Library Documentation: module socketio.kombu_manager in socketio
NAME
socketio.kombu_manager
CLASSES
socketio.pubsub_manager.PubSubManager(socketio.manager.Manager)
KombuManager
class KombuManager(socketio.pubsub_manager.PubSubManager)
| KombuManager(url='amqp://guest:guest@localhost:5672//', channel='socketio', write_only=False, logger=None, json=None, connection_options=None, exchange_options=None, queue_options=None, producer_options=None)
|
| Client manager that uses kombu for inter-process messaging.
|
| This class implements a client manager backend for event sharing across
| multiple processes, using RabbitMQ, Redis or any other messaging mechanism
| supported by `kombu <http://kombu.readthedocs.org/en/latest/>`_.
|
| To use a kombu backend, initialize the :class:`Server` instance as
| follows::
|
| url = 'amqp://user:password@hostname:port//'
| server = socketio.Server(client_manager=socketio.KombuManager(url))
|
| :param url: The connection URL for the backend messaging queue. Example
| connection URLs are ``'amqp://guest:guest@localhost:5672//'``
| and ``'redis://localhost:6379/'`` for RabbitMQ and Redis
| respectively. Consult the `kombu documentation
| <http://kombu.readthedocs.org/en/latest/userguide /connections.html#urls>`_ for more on how to construct
| connection URLs.
| :param channel: The channel name on which the server sends and receives
| notifications. Must be the same in all the servers.
| :param write_only: If set to ``True``, only initialize to emit events. The
| default of ``False`` initializes the class for emitting
| and receiving. A write-only instance can be used
| independently of the server to emit to clients from an
| external process.
| :param logger: a custom logger to log it. If not given, the server logger
| is used.
| :param json: An alternative JSON module to use for encoding and decoding
| packets. Custom json modules must have ``dumps`` and ``loads``
| functions that are compatible with the standard library
| versions. This setting is only used when ``write_only`` is set
| to ``True``. Otherwise the JSON module configured in the
| server is used.
| :param connection_options: additional keyword arguments to be passed to
| ``kombu.Connection()``.
| :param exchange_options: additional keyword arguments to be passed to
| ``kombu.Exchange()``.
| :param queue_options: additional keyword arguments to be passed to
| ``kombu.Queue()``.
| :param producer_options: additional keyword arguments to be passed to
| ``kombu.Producer()``.
|
| Method resolution order:
| KombuManager
| socketio.pubsub_manager.PubSubManager
| socketio.manager.Manager
| socketio.base_manager.BaseManager
| builtins.object
|
| Methods defined here:
|
| __init__(self, url='amqp://guest:guest@localhost:5672//', channel='socketio', write_only=False, logger=None, json=None, connection_options=None, exchange_options=None, queue_options=None, producer_options=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| initialize(self)
| Invoked before the first request is received. Subclasses can add
| their initialization code here.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| name = 'kombu'
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.pubsub_manager.PubSubManager:
|
| can_disconnect(self, sid, namespace)
|
| close_room(self, room, namespace=None)
| Remove all participants from a room.
|
| disconnect(self, sid, namespace=None, **kwargs)
| Register a client disconnect from a namespace.
|
| emit(self, event, data, namespace=None, room=None, skip_sid=None, callback=None, to=None, **kwargs)
| Emit a message to a single client, a room, or all the clients
| connected to the namespace.
|
| This method takes care or propagating the message to all the servers
| that are connected through the message queue.
|
| The parameters are the same as in :meth:`.Server.emit`.
|
| enter_room(self, sid, namespace, room, eio_sid=None)
| Add a client to a room.
|
| leave_room(self, sid, namespace, room)
| Remove a client from a room.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.manager.Manager:
|
| trigger_callback(self, sid, id, data)
| Invoke an application callback.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.base_manager.BaseManager:
|
| basic_close_room(self, room, namespace)
|
| basic_disconnect(self, sid, namespace, **kwargs)
|
| basic_enter_room(self, sid, namespace, room, eio_sid=None)
|
| basic_leave_room(self, sid, namespace, room)
|
| connect(self, eio_sid, namespace)
| Register a client connection to a namespace.
|
| eio_sid_from_sid(self, sid, namespace)
|
| get_namespaces(self)
| Return an iterable with the active namespace names.
|
| get_participants(self, namespace, room)
| Return an iterable with the active participants in a room.
|
| Note that in a multi-server scenario this method only returns the
| participants connect to the server in which the method is called. There
| is currently no functionality to assemble a complete list of users
| across multiple servers.
|
| get_rooms(self, sid, namespace)
| Return the rooms a client is in.
|
| is_connected(self, sid, namespace)
|
| pre_disconnect(self, sid, namespace)
| Put the client in the to-be-disconnected list.
|
| This allows the client data structures to be present while the
| disconnect handler is invoked, but still recognize the fact that the
| client is soon going away.
|
| set_server(self, server)
|
| sid_from_eio_sid(self, eio_sid, namespace)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketio.base_manager.BaseManager:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\socketio\kombu_manager.py
socketio.manager
Python Library Documentation: module socketio.manager in socketio
NAME
socketio.manager
CLASSES
socketio.base_manager.BaseManager(builtins.object)
Manager
class Manager(socketio.base_manager.BaseManager)
| Manage client connections.
|
| This class keeps track of all the clients and the rooms they are in, to
| support the broadcasting of messages. The data used by this class is
| stored in a memory structure, making it appropriate only for single process
| services. More sophisticated storage backends can be implemented by
| subclasses.
|
| Method resolution order:
| Manager
| socketio.base_manager.BaseManager
| builtins.object
|
| Methods defined here:
|
| can_disconnect(self, sid, namespace)
|
| close_room(self, room, namespace)
| Remove all participants from a room.
|
| disconnect(self, sid, namespace, **kwargs)
| Register a client disconnect from a namespace.
|
| emit(self, event, data, namespace, room=None, skip_sid=None, callback=None, to=None, **kwargs)
| Emit a message to a single client, a room, or all the clients
| connected to the namespace.
|
| enter_room(self, sid, namespace, room, eio_sid=None)
| Add a client to a room.
|
| leave_room(self, sid, namespace, room)
| Remove a client from a room.
|
| trigger_callback(self, sid, id, data)
| Invoke an application callback.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.base_manager.BaseManager:
|
| __init__(self)
| Initialize self. See help(type(self)) for accurate signature.
|
| basic_close_room(self, room, namespace)
|
| basic_disconnect(self, sid, namespace, **kwargs)
|
| basic_enter_room(self, sid, namespace, room, eio_sid=None)
|
| basic_leave_room(self, sid, namespace, room)
|
| connect(self, eio_sid, namespace)
| Register a client connection to a namespace.
|
| eio_sid_from_sid(self, sid, namespace)
|
| get_namespaces(self)
| Return an iterable with the active namespace names.
|
| get_participants(self, namespace, room)
| Return an iterable with the active participants in a room.
|
| Note that in a multi-server scenario this method only returns the
| participants connect to the server in which the method is called. There
| is currently no functionality to assemble a complete list of users
| across multiple servers.
|
| get_rooms(self, sid, namespace)
| Return the rooms a client is in.
|
| initialize(self)
| Invoked before the first request is received. Subclasses can add
| their initialization code here.
|
| is_connected(self, sid, namespace)
|
| pre_disconnect(self, sid, namespace)
| Put the client in the to-be-disconnected list.
|
| This allows the client data structures to be present while the
| disconnect handler is invoked, but still recognize the fact that the
| client is soon going away.
|
| set_server(self, server)
|
| sid_from_eio_sid(self, eio_sid, namespace)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketio.base_manager.BaseManager:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
DATA
default_logger = <Logger socketio (WARNING)>
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\socketio\manager.py
socketio.middleware
Python Library Documentation: module socketio.middleware in socketio
NAME
socketio.middleware
CLASSES
engineio.middleware.WSGIApp(builtins.object)
WSGIApp
Middleware
class Middleware(WSGIApp)
| Middleware(socketio_app, wsgi_app=None, socketio_path='socket.io')
|
| This class has been renamed to WSGIApp and is now deprecated.
|
| Method resolution order:
| Middleware
| WSGIApp
| engineio.middleware.WSGIApp
| builtins.object
|
| Methods defined here:
|
| __init__(self, socketio_app, wsgi_app=None, socketio_path='socket.io')
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from engineio.middleware.WSGIApp:
|
| __call__(self, environ, start_response)
| Call self as a function.
|
| not_found(self, start_response)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from engineio.middleware.WSGIApp:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class WSGIApp(engineio.middleware.WSGIApp)
| WSGIApp(socketio_app, wsgi_app=None, static_files=None, socketio_path='socket.io')
|
| WSGI middleware for Socket.IO.
|
| This middleware dispatches traffic to a Socket.IO application. It can also
| serve a list of static files to the client, or forward unrelated HTTP
| traffic to another WSGI application.
|
| :param socketio_app: The Socket.IO server. Must be an instance of the
| ``socketio.Server`` class.
| :param wsgi_app: The WSGI app that receives all other traffic.
| :param static_files: A dictionary with static file mapping rules. See the
| documentation for details on this argument.
| :param socketio_path: The endpoint where the Socket.IO application should
| be installed. The default value is appropriate for
| most cases.
|
| Example usage::
|
| import socketio
| import eventlet
| from . import wsgi_app
|
| sio = socketio.Server()
| app = socketio.WSGIApp(sio, wsgi_app)
| eventlet.wsgi.server(eventlet.listen(('', 8000)), app)
|
| Method resolution order:
| WSGIApp
| engineio.middleware.WSGIApp
| builtins.object
|
| Methods defined here:
|
| __init__(self, socketio_app, wsgi_app=None, static_files=None, socketio_path='socket.io')
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from engineio.middleware.WSGIApp:
|
| __call__(self, environ, start_response)
| Call self as a function.
|
| not_found(self, start_response)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from engineio.middleware.WSGIApp:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\socketio\middleware.py
socketio.namespace
Python Library Documentation: module socketio.namespace in socketio
NAME
socketio.namespace
CLASSES
socketio.base_namespace.BaseClientNamespace(socketio.base_namespace.BaseNamespace)
ClientNamespace
socketio.base_namespace.BaseServerNamespace(socketio.base_namespace.BaseNamespace)
Namespace
class ClientNamespace(socketio.base_namespace.BaseClientNamespace)
| ClientNamespace(namespace=None)
|
| Base class for client-side class-based namespaces.
|
| A class-based namespace is a class that contains all the event handlers
| for a Socket.IO namespace. The event handlers are methods of the class
| with the prefix ``on_``, such as ``on_connect``, ``on_disconnect``,
| ``on_message``, ``on_json``, and so on.
|
| :param namespace: The Socket.IO namespace to be used with all the event
| handlers defined in this class. If this argument is
| omitted, the default namespace is used.
|
| Method resolution order:
| ClientNamespace
| socketio.base_namespace.BaseClientNamespace
| socketio.base_namespace.BaseNamespace
| builtins.object
|
| Methods defined here:
|
| call(self, event, data=None, namespace=None, timeout=None)
| Emit a custom event to the server and wait for the response.
|
| The only difference with the :func:`socketio.Client.call` method is
| that when the ``namespace`` argument is not given the namespace
| associated with the class is used.
|
| disconnect(self)
| Disconnect from the server.
|
| The only difference with the :func:`socketio.Client.disconnect` method
| is that when the ``namespace`` argument is not given the namespace
| associated with the class is used.
|
| emit(self, event, data=None, namespace=None, callback=None)
| Emit a custom event to the server.
|
| The only difference with the :func:`socketio.Client.emit` method is
| that when the ``namespace`` argument is not given the namespace
| associated with the class is used.
|
| send(self, data, room=None, namespace=None, callback=None)
| Send a message to the server.
|
| The only difference with the :func:`socketio.Client.send` method is
| that when the ``namespace`` argument is not given the namespace
| associated with the class is used.
|
| trigger_event(self, event, *args)
| Dispatch an event to the proper handler method.
|
| In the most common usage, this method is not overloaded by subclasses,
| as it performs the routing of events to methods. However, this
| method can be overridden if special dispatching rules are needed, or if
| having a single method that catches all events is desired.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.base_namespace.BaseClientNamespace:
|
| __init__(self, namespace=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.base_namespace.BaseNamespace:
|
| is_asyncio_based(self)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketio.base_namespace.BaseNamespace:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class Namespace(socketio.base_namespace.BaseServerNamespace)
| Namespace(namespace=None)
|
| Base class for server-side class-based namespaces.
|
| A class-based namespace is a class that contains all the event handlers
| for a Socket.IO namespace. The event handlers are methods of the class
| with the prefix ``on_``, such as ``on_connect``, ``on_disconnect``,
| ``on_message``, ``on_json``, and so on.
|
| :param namespace: The Socket.IO namespace to be used with all the event
| handlers defined in this class. If this argument is
| omitted, the default namespace is used.
|
| Method resolution order:
| Namespace
| socketio.base_namespace.BaseServerNamespace
| socketio.base_namespace.BaseNamespace
| builtins.object
|
| Methods defined here:
|
| call(self, event, data=None, to=None, sid=None, namespace=None, timeout=None, ignore_queue=False)
| Emit a custom event to a client and wait for the response.
|
| The only difference with the :func:`socketio.Server.call` method is
| that when the ``namespace`` argument is not given the namespace
| associated with the class is used.
|
| close_room(self, room, namespace=None)
| Close a room.
|
| The only difference with the :func:`socketio.Server.close_room` method
| is that when the ``namespace`` argument is not given the namespace
| associated with the class is used.
|
| disconnect(self, sid, namespace=None)
| Disconnect a client.
|
| The only difference with the :func:`socketio.Server.disconnect` method
| is that when the ``namespace`` argument is not given the namespace
| associated with the class is used.
|
| emit(self, event, data=None, to=None, room=None, skip_sid=None, namespace=None, callback=None, ignore_queue=False)
| Emit a custom event to one or more connected clients.
|
| The only difference with the :func:`socketio.Server.emit` method is
| that when the ``namespace`` argument is not given the namespace
| associated with the class is used.
|
| enter_room(self, sid, room, namespace=None)
| Enter a room.
|
| The only difference with the :func:`socketio.Server.enter_room` method
| is that when the ``namespace`` argument is not given the namespace
| associated with the class is used.
|
| get_session(self, sid, namespace=None)
| Return the user session for a client.
|
| The only difference with the :func:`socketio.Server.get_session`
| method is that when the ``namespace`` argument is not given the
| namespace associated with the class is used.
|
| leave_room(self, sid, room, namespace=None)
| Leave a room.
|
| The only difference with the :func:`socketio.Server.leave_room` method
| is that when the ``namespace`` argument is not given the namespace
| associated with the class is used.
|
| save_session(self, sid, session, namespace=None)
| Store the user session for a client.
|
| The only difference with the :func:`socketio.Server.save_session`
| method is that when the ``namespace`` argument is not given the
| namespace associated with the class is used.
|
| send(self, data, to=None, room=None, skip_sid=None, namespace=None, callback=None, ignore_queue=False)
| Send a message to one or more connected clients.
|
| The only difference with the :func:`socketio.Server.send` method is
| that when the ``namespace`` argument is not given the namespace
| associated with the class is used.
|
| session(self, sid, namespace=None)
| Return the user session for a client with context manager syntax.
|
| The only difference with the :func:`socketio.Server.session` method is
| that when the ``namespace`` argument is not given the namespace
| associated with the class is used.
|
| trigger_event(self, event, *args)
| Dispatch an event to the proper handler method.
|
| In the most common usage, this method is not overloaded by subclasses,
| as it performs the routing of events to methods. However, this
| method can be overridden if special dispatching rules are needed, or if
| having a single method that catches all events is desired.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.base_namespace.BaseServerNamespace:
|
| __init__(self, namespace=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| rooms(self, sid, namespace=None)
| Return the rooms a client is in.
|
| The only difference with the :func:`socketio.Server.rooms` method is
| that when the ``namespace`` argument is not given the namespace
| associated with the class is used.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.base_namespace.BaseNamespace:
|
| is_asyncio_based(self)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketio.base_namespace.BaseNamespace:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\socketio\namespace.py
socketio.packet
Python Library Documentation: module socketio.packet in socketio
NAME
socketio.packet
CLASSES
builtins.object
Packet
class Packet(builtins.object)
| Packet(packet_type=2, data=None, namespace=None, id=None, binary=None, encoded_packet=None)
|
| Socket.IO packet.
|
| Methods defined here:
|
| __init__(self, packet_type=2, data=None, namespace=None, id=None, binary=None, encoded_packet=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| add_attachment(self, attachment)
|
| decode(self, encoded_packet)
| Decode a transmitted package.
|
| The return value indicates how many binary attachment packets are
| necessary to fully decode the packet.
|
| encode(self)
| Encode the packet for transmission.
|
| If the packet contains binary elements, this function returns a list
| of packets where the first is the original packet with placeholders for
| the binary components and the remaining ones the binary attachments.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| data_is_binary(data)
| Check if the data contains binary components.
|
| deconstruct_binary(data)
| Extract binary components in the packet.
|
| reconstruct_binary(data, attachments)
| Reconstruct a decoded packet using the given list of binary
| attachments.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| json = <module 'engineio.json' from 'C:\\Users\\Youse\\...ython312\\Li...
| JSON-compatible module with sane defaults.
|
|
| uses_binary_events = True
DATA
ACK = 3
BINARY_ACK = 6
BINARY_EVENT = 5
CONNECT = 0
CONNECT_ERROR = 4
DISCONNECT = 1
EVENT = 2
packet_names = ['CONNECT', 'DISCONNECT', 'EVENT', 'ACK', 'CONNECT_ERRO...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\socketio\packet.py
socketio.pubsub_manager
Python Library Documentation: module socketio.pubsub_manager in socketio
NAME
socketio.pubsub_manager
CLASSES
socketio.manager.Manager(socketio.base_manager.BaseManager)
PubSubManager
class PubSubManager(socketio.manager.Manager)
| PubSubManager(channel='socketio', write_only=False, logger=None, json=None)
|
| Manage a client list attached to a pub/sub backend.
|
| This is a base class that enables multiple servers to share the list of
| clients, with the servers communicating events through a pub/sub backend.
| The use of a pub/sub backend also allows any client connected to the
| backend to emit events addressed to Socket.IO clients.
|
| The actual backends must be implemented by subclasses, this class only
| provides a pub/sub generic framework.
|
| :param channel: The channel name on which the server sends and receives
| notifications.
| :param write_only: If set to ``True``, only initialize to emit events. The
| default of ``False`` initializes the class for emitting
| and receiving. A write-only instance can be used
| independently of the server to emit to clients from an
| external process.
| :param logger: a custom logger to log it. If not given, the server logger
| is used.
| :param json: An alternative JSON module to use for encoding and decoding
| packets. Custom json modules must have ``dumps`` and ``loads``
| functions that are compatible with the standard library
| versions. This setting is only used when ``write_only`` is set
| to ``True``. Otherwise the JSON module configured in the
| server is used.
|
| Method resolution order:
| PubSubManager
| socketio.manager.Manager
| socketio.base_manager.BaseManager
| builtins.object
|
| Methods defined here:
|
| __init__(self, channel='socketio', write_only=False, logger=None, json=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| can_disconnect(self, sid, namespace)
|
| close_room(self, room, namespace=None)
| Remove all participants from a room.
|
| disconnect(self, sid, namespace=None, **kwargs)
| Register a client disconnect from a namespace.
|
| emit(self, event, data, namespace=None, room=None, skip_sid=None, callback=None, to=None, **kwargs)
| Emit a message to a single client, a room, or all the clients
| connected to the namespace.
|
| This method takes care or propagating the message to all the servers
| that are connected through the message queue.
|
| The parameters are the same as in :meth:`.Server.emit`.
|
| enter_room(self, sid, namespace, room, eio_sid=None)
| Add a client to a room.
|
| initialize(self)
| Invoked before the first request is received. Subclasses can add
| their initialization code here.
|
| leave_room(self, sid, namespace, room)
| Remove a client from a room.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| name = 'pubsub'
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.manager.Manager:
|
| trigger_callback(self, sid, id, data)
| Invoke an application callback.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.base_manager.BaseManager:
|
| basic_close_room(self, room, namespace)
|
| basic_disconnect(self, sid, namespace, **kwargs)
|
| basic_enter_room(self, sid, namespace, room, eio_sid=None)
|
| basic_leave_room(self, sid, namespace, room)
|
| connect(self, eio_sid, namespace)
| Register a client connection to a namespace.
|
| eio_sid_from_sid(self, sid, namespace)
|
| get_namespaces(self)
| Return an iterable with the active namespace names.
|
| get_participants(self, namespace, room)
| Return an iterable with the active participants in a room.
|
| Note that in a multi-server scenario this method only returns the
| participants connect to the server in which the method is called. There
| is currently no functionality to assemble a complete list of users
| across multiple servers.
|
| get_rooms(self, sid, namespace)
| Return the rooms a client is in.
|
| is_connected(self, sid, namespace)
|
| pre_disconnect(self, sid, namespace)
| Put the client in the to-be-disconnected list.
|
| This allows the client data structures to be present while the
| disconnect handler is invoked, but still recognize the fact that the
| client is soon going away.
|
| set_server(self, server)
|
| sid_from_eio_sid(self, eio_sid, namespace)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketio.base_manager.BaseManager:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\socketio\pubsub_manager.py
socketio.redis_manager
Python Library Documentation: module socketio.redis_manager in socketio
NAME
socketio.redis_manager
CLASSES
socketio.pubsub_manager.PubSubManager(socketio.manager.Manager)
RedisManager
class RedisManager(socketio.pubsub_manager.PubSubManager)
| RedisManager(url='redis://localhost:6379/0', channel='socketio', write_only=False, logger=None, json=None, redis_options=None)
|
| Redis based client manager.
|
| This class implements a Redis backend for event sharing across multiple
| processes. Only kept here as one more example of how to build a custom
| backend, since the kombu backend is perfectly adequate to support a Redis
| message queue.
|
| To use a Redis backend, initialize the :class:`Server` instance as
| follows::
|
| url = 'redis://hostname:port/0'
| server = socketio.Server(client_manager=socketio.RedisManager(url))
|
| :param url: The connection URL for the Redis server. For a default Redis
| store running on the same host, use ``redis://``. To use a
| TLS connection, use ``rediss://``. To use Redis Sentinel, use
| ``redis+sentinel://`` with a comma-separated list of hosts
| and the service name after the db in the URL path. Example:
| ``redis+sentinel://user:pw@host1:1234,host2:2345/0/myredis``.
| :param channel: The channel name on which the server sends and receives
| notifications. Must be the same in all the servers.
| :param write_only: If set to ``True``, only initialize to emit events. The
| default of ``False`` initializes the class for emitting
| and receiving. A write-only instance can be used
| independently of the server to emit to clients from an
| external process.
| :param logger: a custom logger to log it. If not given, the server logger
| is used.
| :param json: An alternative JSON module to use for encoding and decoding
| packets. Custom json modules must have ``dumps`` and ``loads``
| functions that are compatible with the standard library
| versions. This setting is only used when ``write_only`` is set
| to ``True``. Otherwise the JSON module configured in the
| server is used.
| :param redis_options: additional keyword arguments to be passed to
| ``Redis.from_url()`` or ``Sentinel()``.
|
| Method resolution order:
| RedisManager
| socketio.pubsub_manager.PubSubManager
| socketio.manager.Manager
| socketio.base_manager.BaseManager
| builtins.object
|
| Methods defined here:
|
| __init__(self, url='redis://localhost:6379/0', channel='socketio', write_only=False, logger=None, json=None, redis_options=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| initialize(self)
| Invoked before the first request is received. Subclasses can add
| their initialization code here.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| name = 'redis'
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.pubsub_manager.PubSubManager:
|
| can_disconnect(self, sid, namespace)
|
| close_room(self, room, namespace=None)
| Remove all participants from a room.
|
| disconnect(self, sid, namespace=None, **kwargs)
| Register a client disconnect from a namespace.
|
| emit(self, event, data, namespace=None, room=None, skip_sid=None, callback=None, to=None, **kwargs)
| Emit a message to a single client, a room, or all the clients
| connected to the namespace.
|
| This method takes care or propagating the message to all the servers
| that are connected through the message queue.
|
| The parameters are the same as in :meth:`.Server.emit`.
|
| enter_room(self, sid, namespace, room, eio_sid=None)
| Add a client to a room.
|
| leave_room(self, sid, namespace, room)
| Remove a client from a room.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.manager.Manager:
|
| trigger_callback(self, sid, id, data)
| Invoke an application callback.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.base_manager.BaseManager:
|
| basic_close_room(self, room, namespace)
|
| basic_disconnect(self, sid, namespace, **kwargs)
|
| basic_enter_room(self, sid, namespace, room, eio_sid=None)
|
| basic_leave_room(self, sid, namespace, room)
|
| connect(self, eio_sid, namespace)
| Register a client connection to a namespace.
|
| eio_sid_from_sid(self, sid, namespace)
|
| get_namespaces(self)
| Return an iterable with the active namespace names.
|
| get_participants(self, namespace, room)
| Return an iterable with the active participants in a room.
|
| Note that in a multi-server scenario this method only returns the
| participants connect to the server in which the method is called. There
| is currently no functionality to assemble a complete list of users
| across multiple servers.
|
| get_rooms(self, sid, namespace)
| Return the rooms a client is in.
|
| is_connected(self, sid, namespace)
|
| pre_disconnect(self, sid, namespace)
| Put the client in the to-be-disconnected list.
|
| This allows the client data structures to be present while the
| disconnect handler is invoked, but still recognize the fact that the
| client is soon going away.
|
| set_server(self, server)
|
| sid_from_eio_sid(self, eio_sid, namespace)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketio.base_manager.BaseManager:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FUNCTIONS
parse_redis_sentinel_url(url)
Parse a Redis Sentinel URL with the format:
redis+sentinel://[:password]@host1:port1,host2:port2,.../db/service_name
DATA
ValkeyError = None
valkey = None
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\socketio\redis_manager.py
socketio.server
Python Library Documentation: module socketio.server in socketio
NAME
socketio.server
CLASSES
socketio.base_server.BaseServer(builtins.object)
Server
class Server(socketio.base_server.BaseServer)
| Server(client_manager=None, logger=False, serializer='default', json=None, async_handlers=True, always_connect=False, namespaces=None, **kwargs)
|
| A Socket.IO server.
|
| This class implements a fully compliant Socket.IO web server with support
| for websocket and long-polling transports.
|
| :param client_manager: The client manager instance that will manage the
| client list. When this is omitted, the client list
| is stored in an in-memory structure, so the use of
| multiple connected servers is not possible.
| :param logger: To enable logging set to ``True`` or pass a logger object to
| use. To disable logging set to ``False``. The default is
| ``False``. Note that fatal errors are logged even when
| ``logger`` is ``False``.
| :param serializer: The serialization method to use when transmitting
| packets. Valid values are ``'default'``, ``'pickle'``,
| ``'msgpack'`` and ``'cbor'``. Alternatively, a subclass
| of the :class:`Packet` class with custom implementations
| of the ``encode()`` and ``decode()`` methods can be
| provided. Client and server must use compatible
| serializers.
| :param json: An alternative JSON module to use for encoding and decoding
| packets. Custom json modules must have ``dumps`` and ``loads``
| functions that are compatible with the standard library
| versions. This is a process-wide setting, all instantiated
| servers and clients must use the same JSON module.
| :param async_handlers: If set to ``True``, event handlers for a client are
| executed in separate threads. To run handlers for a
| client synchronously, set to ``False``. The default
| is ``True``.
| :param always_connect: When set to ``False``, new connections are
| provisory until the connect handler returns
| something other than ``False``, at which point they
| are accepted. When set to ``True``, connections are
| immediately accepted, and then if the connect
| handler returns ``False`` a disconnect is issued.
| Set to ``True`` if you need to emit events from the
| connect handler and your client is confused when it
| receives events before the connection acceptance.
| In any other case use the default of ``False``.
| :param namespaces: a list of namespaces that are accepted, in addition to
| any namespaces for which handlers have been defined. The
| default is `['/']`, which always accepts connections to
| the default namespace. Set to `'*'` to accept all
| namespaces.
| :param kwargs: Connection parameters for the underlying Engine.IO server.
|
| The Engine.IO configuration supports the following settings:
|
| :param async_mode: The asynchronous model to use. See the Deployment
| section in the documentation for a description of the
| available options. Valid async modes are
| ``'threading'``, ``'eventlet'``, ``'gevent'`` and
| ``'gevent_uwsgi'``. If this argument is not given,
| ``'eventlet'`` is tried first, then ``'gevent_uwsgi'``,
| then ``'gevent'``, and finally ``'threading'``.
| The first async mode that has all its dependencies
| installed is then one that is chosen.
| :param ping_interval: The interval in seconds at which the server pings
| the client. The default is 25 seconds. For advanced
| control, a two element tuple can be given, where
| the first number is the ping interval and the second
| is a grace period added by the server.
| :param ping_timeout: The time in seconds that the client waits for the
| server to respond before disconnecting. The default
| is 20 seconds.
| :param max_http_buffer_size: The maximum size that is accepted for incoming
| messages. The default is 1,000,000 bytes. In
| spite of its name, the value set in this
| argument is enforced for HTTP long-polling and
| WebSocket connections.
| :param allow_upgrades: Whether to allow transport upgrades or not. The
| default is ``True``.
| :param http_compression: Whether to compress packages when using the
| polling transport. The default is ``True``.
| :param compression_threshold: Only compress messages when their byte size
| is greater than this value. The default is
| 1024 bytes.
| :param cookie: If set to a string, it is the name of the HTTP cookie the
| server sends back to the client containing the client
| session id. If set to a dictionary, the ``'name'`` key
| contains the cookie name and other keys define cookie
| attributes, where the value of each attribute can be a
| string, a callable with no arguments, or a boolean. If set
| to ``None`` (the default), a cookie is not sent to the
| client.
| :param cors_allowed_origins: Origin or list of origins that are allowed to
| connect to this server. Only the same origin
| is allowed by default. Set this argument to
| ``'*'`` to allow all origins, or to ``[]`` to
| disable CORS handling.
| :param cors_credentials: Whether credentials (cookies, authentication) are
| allowed in requests to this server. The default is
| ``True``.
| :param monitor_clients: If set to ``True``, a background task will ensure
| inactive clients are closed. Set to ``False`` to
| disable the monitoring task (not recommended). The
| default is ``True``.
| :param transports: The list of allowed transports. Valid transports
| are ``'polling'`` and ``'websocket'``. Defaults to
| ``['polling', 'websocket']``.
| :param engineio_logger: To enable Engine.IO logging set to ``True`` or pass
| a logger object to use. To disable logging set to
| ``False``. The default is ``False``. Note that
| fatal errors are logged even when
| ``engineio_logger`` is ``False``.
|
| Method resolution order:
| Server
| socketio.base_server.BaseServer
| builtins.object
|
| Methods defined here:
|
| call(self, event, data=None, to=None, sid=None, namespace=None, timeout=60, ignore_queue=False)
| Emit a custom event to a client and wait for the response.
|
| This method issues an emit with a callback and waits for the callback
| to be invoked before returning. If the callback isn't invoked before
| the timeout, then a ``TimeoutError`` exception is raised. If the
| Socket.IO connection drops during the wait, this method still waits
| until the specified timeout.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used.
| :param data: The data to send to the client or clients. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
| :param to: The session ID of the recipient client.
| :param sid: Alias for the ``to`` parameter.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the event is emitted to the
| default namespace.
| :param timeout: The waiting timeout. If the timeout is reached before
| the client acknowledges the event, then a
| ``TimeoutError`` exception is raised.
| :param ignore_queue: Only used when a message queue is configured. If
| set to ``True``, the event is emitted to the
| client directly, without going through the queue.
| This is more efficient, but only works when a
| single server process is used. It is recommended
| to always leave this parameter with its default
| value of ``False``.
|
| Note: this method is not thread safe. If multiple threads are emitting
| at the same time to the same client, then messages composed of
| multiple packets may end up being sent in an incorrect sequence. Use
| standard concurrency solutions (such as a Lock object) to prevent this
| situation.
|
| close_room(self, room, namespace=None)
| Close a room.
|
| This function removes all the clients from the given room.
|
| :param room: Room name.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the default namespace is used.
|
| disconnect(self, sid, namespace=None, ignore_queue=False)
| Disconnect a client.
|
| :param sid: Session ID of the client.
| :param namespace: The Socket.IO namespace to disconnect. If this
| argument is omitted the default namespace is used.
| :param ignore_queue: Only used when a message queue is configured. If
| set to ``True``, the disconnect is processed
| locally, without broadcasting on the queue. It is
| recommended to always leave this parameter with
| its default value of ``False``.
|
| emit(self, event, data=None, to=None, room=None, skip_sid=None, namespace=None, callback=None, ignore_queue=False)
| Emit a custom event to one or more connected clients.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used.
| :param data: The data to send to the client or clients. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
| :param to: The recipient of the message. This can be set to the
| session ID of a client to address only that client, to any
| custom room created by the application to address all
| the clients in that room, or to a list of custom room
| names. If this argument is omitted the event is broadcasted
| to all connected clients.
| :param room: Alias for the ``to`` parameter.
| :param skip_sid: The session ID of a client to skip when broadcasting
| to a room or to all clients. This can be used to
| prevent a message from being sent to the sender. To
| skip multiple sids, pass a list.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the event is emitted to the
| default namespace.
| :param callback: If given, this function will be called to acknowledge
| the client has received the message. The arguments
| that will be passed to the function are those provided
| by the client. Callback functions can only be used
| when addressing an individual client.
| :param ignore_queue: Only used when a message queue is configured. If
| set to ``True``, the event is emitted to the
| clients directly, without going through the queue.
| This is more efficient, but only works when a
| single server process is used. It is recommended
| to always leave this parameter with its default
| value of ``False``.
|
| Note: this method is not thread safe. If multiple threads are emitting
| at the same time to the same client, then messages composed of
| multiple packets may end up being sent in an incorrect sequence. Use
| standard concurrency solutions (such as a Lock object) to prevent this
| situation.
|
| enter_room(self, sid, room, namespace=None)
| Enter a room.
|
| This function adds the client to a room. The :func:`emit` and
| :func:`send` functions can optionally broadcast events to all the
| clients in a room.
|
| :param sid: Session ID of the client.
| :param room: Room name. If the room does not exist it is created.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the default namespace is used.
|
| get_session(self, sid, namespace=None)
| Return the user session for a client.
|
| :param sid: The session id of the client.
| :param namespace: The Socket.IO namespace. If this argument is omitted
| the default namespace is used.
|
| The return value is a dictionary. Modifications made to this
| dictionary are not guaranteed to be preserved unless
| ``save_session()`` is called, or when the ``session`` context manager
| is used.
|
| handle_request(self, environ, start_response)
| Handle an HTTP request from the client.
|
| This is the entry point of the Socket.IO application, using the same
| interface as a WSGI application. For the typical usage, this function
| is invoked by the :class:`Middleware` instance, but it can be invoked
| directly when the middleware is not used.
|
| :param environ: The WSGI environment.
| :param start_response: The WSGI ``start_response`` function.
|
| This function returns the HTTP response body to deliver to the client
| as a byte sequence.
|
| instrument(self, auth=None, mode='development', read_only=False, server_id=None, namespace='/admin', server_stats_interval=2)
| Instrument the Socket.IO server for monitoring with the `Socket.IO
| Admin UI <https://socket.io/docs/v4/admin-ui/>`_.
|
| :param auth: Authentication credentials for Admin UI access. Set to a
| dictionary with the expected login (usually ``username``
| and ``password``) or a list of dictionaries if more than
| one set of credentials need to be available. For more
| complex authentication methods, set to a callable that
| receives the authentication dictionary as an argument and
| returns ``True`` if the user is allowed or ``False``
| otherwise. To disable authentication, set this argument to
| ``False`` (not recommended, never do this on a production
| server).
| :param mode: The reporting mode. The default is ``'development'``,
| which is best used while debugging, as it may have a
| significant performance effect. Set to ``'production'`` to
| reduce the amount of information that is reported to the
| admin UI.
| :param read_only: If set to ``True``, the admin interface will be
| read-only, with no option to modify room assignments
| or disconnect clients. The default is ``False``.
| :param server_id: The server name to use for this server. If this
| argument is omitted, the server generates its own
| name.
| :param namespace: The Socket.IO namespace to use for the admin
| interface. The default is ``/admin``.
| :param server_stats_interval: The interval in seconds at which the
| server emits a summary of it stats to all
| connected admins.
|
| leave_room(self, sid, room, namespace=None)
| Leave a room.
|
| This function removes the client from a room.
|
| :param sid: Session ID of the client.
| :param room: Room name.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the default namespace is used.
|
| save_session(self, sid, session, namespace=None)
| Store the user session for a client.
|
| :param sid: The session id of the client.
| :param session: The session dictionary.
| :param namespace: The Socket.IO namespace. If this argument is omitted
| the default namespace is used.
|
| send(self, data, to=None, room=None, skip_sid=None, namespace=None, callback=None, ignore_queue=False)
| Send a message to one or more connected clients.
|
| This function emits an event with the name ``'message'``. Use
| :func:`emit` to issue custom event names.
|
| :param data: The data to send to the client or clients. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
| :param to: The recipient of the message. This can be set to the
| session ID of a client to address only that client, to any
| any custom room created by the application to address all
| the clients in that room, or to a list of custom room
| names. If this argument is omitted the event is broadcasted
| to all connected clients.
| :param room: Alias for the ``to`` parameter.
| :param skip_sid: The session ID of a client to skip when broadcasting
| to a room or to all clients. This can be used to
| prevent a message from being sent to the sender. To
| skip multiple sids, pass a list.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the event is emitted to the
| default namespace.
| :param callback: If given, this function will be called to acknowledge
| the client has received the message. The arguments
| that will be passed to the function are those provided
| by the client. Callback functions can only be used
| when addressing an individual client.
| :param ignore_queue: Only used when a message queue is configured. If
| set to ``True``, the event is emitted to the
| clients directly, without going through the queue.
| This is more efficient, but only works when a
| single server process is used. It is recommended
| to always leave this parameter with its default
| value of ``False``.
|
| session(self, sid, namespace=None)
| Return the user session for a client with context manager syntax.
|
| :param sid: The session id of the client.
|
| This is a context manager that returns the user session dictionary for
| the client. Any changes that are made to this dictionary inside the
| context manager block are saved back to the session. Example usage::
|
| @sio.on('connect')
| def on_connect(sid, environ):
| username = authenticate_user(environ)
| if not username:
| return False
| with sio.session(sid) as session:
| session['username'] = username
|
| @sio.on('message')
| def on_message(sid, msg):
| with sio.session(sid) as session:
| print('received message from ', session['username'])
|
| shutdown(self)
| Stop Socket.IO background tasks.
|
| This method stops all background activity initiated by the Socket.IO
| server. It must be called before shutting down the web server.
|
| sleep(self, seconds=0)
| Sleep for the requested amount of time using the appropriate async
| model.
|
| This is a utility function that applications can use to put a task to
| sleep without having to worry about using the correct call for the
| selected async mode.
|
| start_background_task(self, target, *args, **kwargs)
| Start a background task using the appropriate async model.
|
| This is a utility function that applications can use to start a
| background task using the method that is compatible with the
| selected async mode.
|
| :param target: the target function to execute.
| :param args: arguments to pass to the function.
| :param kwargs: keyword arguments to pass to the function.
|
| This function returns an object that represents the background task,
| on which the ``join()`` methond can be invoked to wait for the task to
| complete.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.base_server.BaseServer:
|
| __init__(self, client_manager=None, logger=False, serializer='default', json=None, async_handlers=True, always_connect=False, namespaces=None, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| event(self, *args, **kwargs)
| Decorator to register an event handler.
|
| This is a simplified version of the ``on()`` method that takes the
| event name from the decorated function.
|
| Example usage::
|
| @sio.event
| def my_event(data):
| print('Received data: ', data)
|
| The above example is equivalent to::
|
| @sio.on('my_event')
| def my_event(data):
| print('Received data: ', data)
|
| A custom namespace can be given as an argument to the decorator::
|
| @sio.event(namespace='/test')
| def my_event(data):
| print('Received data: ', data)
|
| get_environ(self, sid, namespace=None)
| Return the WSGI environ dictionary for a client.
|
| :param sid: The session of the client.
| :param namespace: The Socket.IO namespace. If this argument is omitted
| the default namespace is used.
|
| is_asyncio_based(self)
|
| on(self, event, handler=None, namespace=None)
| Register an event handler.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used. The ``'*'`` event name
| can be used to define a catch-all event handler.
| :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. A catch-all namespace can be
| defined by passing ``'*'`` as the namespace.
|
| Example usage::
|
| # as a decorator:
| @sio.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)
| sio.send(sid, 'response')
| socket_io.on('message', namespace='/chat', handler=message_handler)
|
| The arguments passed to the handler function depend on the event type:
|
| - The ``'connect'`` event handler receives the ``sid`` (session ID) for
| the client and the WSGI environment dictionary as arguments.
| - The ``'disconnect'`` handler receives the ``sid`` for the client as
| only argument.
| - The ``'message'`` handler and handlers for custom event names receive
| the ``sid`` for the client and the message payload as arguments. Any
| values returned from a message handler will be passed to the client's
| acknowledgement callback function if it exists.
| - A catch-all event handler receives the event name as first argument,
| followed by any arguments specific to the event.
| - A catch-all namespace event handler receives the namespace as first
| argument, followed by any arguments specific to the event.
| - A combined catch-all namespace and catch-all event handler receives
| the event name as first argument and the namespace as second
| argument, followed by any arguments specific to the event.
|
| register_namespace(self, namespace_handler)
| Register a namespace handler object.
|
| :param namespace_handler: An instance of a :class:`Namespace`
| subclass that handles all the event traffic
| for a namespace.
|
| rooms(self, sid, namespace=None)
| Return the rooms a client is in.
|
| :param sid: Session ID of the client.
| :param namespace: The Socket.IO namespace for the event. If this
| argument is omitted the default namespace is used.
|
| transport(self, sid, namespace=None)
| Return the name of the transport used by the client.
|
| The two possible values returned by this function are ``'polling'``
| and ``'websocket'``.
|
| :param sid: The session of the client.
| :param namespace: The Socket.IO namespace. If this argument is omitted
| the default namespace is used.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketio.base_server.BaseServer:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketio.base_server.BaseServer:
|
| reason = <class 'engineio.base_server.BaseServer.reason'>
| Disconnection reasons.
|
|
| reserved_events = ['connect', 'disconnect']
DATA
default_logger = <Logger socketio.server (WARNING)>
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\socketio\server.py
socketio.simple_client
Python Library Documentation: module socketio.simple_client in socketio
NAME
socketio.simple_client
CLASSES
builtins.object
SimpleClient
class SimpleClient(builtins.object)
| SimpleClient(*args, **kwargs)
|
| A Socket.IO client.
|
| This class implements a simple, yet fully compliant Socket.IO web client
| with support for websocket and long-polling transports.
|
| The positional and keyword arguments given in the constructor are passed
| to the underlying :func:`socketio.Client` object.
|
| Methods defined here:
|
| __enter__(self)
|
| __exit__(self, exc_type, exc_val, exc_tb)
|
| __init__(self, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| call(self, event, data=None, timeout=60)
| Emit an event to the server and wait for a response.
|
| This method issues an emit and waits for the server to provide a
| response or acknowledgement. If the response does not arrive before the
| timeout, then a ``TimeoutError`` exception is raised.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used.
| :param data: The data to send to the server. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
| :param timeout: The waiting timeout. If the timeout is reached before
| the server acknowledges the event, then a
| ``TimeoutError`` exception is raised.
|
| connect(self, url, headers={}, auth=None, transports=None, namespace='/', socketio_path='socket.io', wait_timeout=5)
| Connect to a Socket.IO server.
|
| :param url: The URL of the Socket.IO server. It can include custom
| query string parameters if required by the server. If a
| function is provided, the client will invoke it to obtain
| the URL each time a connection or reconnection is
| attempted.
| :param headers: A dictionary with custom headers to send with the
| connection request. If a function is provided, the
| client will invoke it to obtain the headers dictionary
| each time a connection or reconnection is attempted.
| :param auth: Authentication data passed to the server with the
| connection request, normally a dictionary with one or
| more string key/value pairs. If a function is provided,
| the client will invoke it to obtain the authentication
| data each time a connection or reconnection is attempted.
| :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 namespace: The namespace to connect to as a string. If not
| given, the default namespace ``/`` is used.
| :param socketio_path: The endpoint where the Socket.IO server is
| installed. The default value is appropriate for
| most cases.
| :param wait_timeout: How long the client should wait for the
| connection to be established. The default is 5
| seconds.
|
| disconnect(self)
| Disconnect from the server.
|
| emit(self, event, data=None)
| Emit an event to the server.
|
| :param event: The event name. It can be any string. The event names
| ``'connect'``, ``'message'`` and ``'disconnect'`` are
| reserved and should not be used.
| :param data: The data to send to the server. Data can be of
| type ``str``, ``bytes``, ``list`` or ``dict``. To send
| multiple arguments, use a tuple where each element is of
| one of the types indicated above.
|
| This method schedules the event to be sent out and returns, without
| actually waiting for its delivery. In cases where the client needs to
| ensure that the event was received, :func:`socketio.SimpleClient.call`
| should be used instead.
|
| receive(self, timeout=None)
| Wait for an event from the server.
|
| :param timeout: The waiting timeout. If the timeout is reached before
| the server acknowledges the event, then a
| ``TimeoutError`` exception is raised.
|
| The return value is a list with the event name as the first element. If
| the server included arguments with the event, they are returned as
| additional list elements.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| sid
| The session ID received from the server.
|
| The session ID is not guaranteed to remain constant throughout the life
| of the connection, as reconnections can cause it to change.
|
| transport
| The name of the transport currently in use.
|
| The transport is returned as a string and can be one of ``polling``
| and ``websocket``.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| client_class = <class 'socketio.client.Client'>
| A Socket.IO client.
|
| This class implements a fully compliant Socket.IO web client with support
| for websocket and long-polling transports.
|
| :param reconnection: ``True`` if the client should automatically attempt to
| reconnect to the server after an interruption, or
| ``False`` to not reconnect. The default is ``True``.
| :param reconnection_attempts: How many reconnection attempts to issue
| before giving up, or 0 for infinite attempts.
| The default is 0.
| :param reconnection_delay: How long to wait in seconds before the first
| reconnection attempt. Each successive attempt
| doubles this delay.
| :param reconnection_delay_max: The maximum delay between reconnection
| attempts.
| :param randomization_factor: Randomization amount for each delay between
| reconnection attempts. The default is 0.5,
| which means that each delay is randomly
| adjusted by +/- 50%.
| :param logger: To enable logging set to ``True`` or pass a logger object to
| use. To disable logging set to ``False``. The default is
| ``False``. Note that fatal errors are logged even when
| ``logger`` is ``False``.
| :param serializer: The serialization method to use when transmitting
| packets. Valid values are ``'default'``, ``'pickle'``,
| ``'msgpack'`` and ``'cbor'``. Alternatively, a subclass
| of the :class:`Packet` class with custom implementations
| of the ``encode()`` and ``decode()`` methods can be
| provided. Client and server must use compatible
| serializers.
| :param json: An alternative JSON module to use for encoding and decoding
| packets. Custom json modules must have ``dumps`` and ``loads``
| functions that are compatible with the standard library
| versions. This is a process-wide setting, all instantiated
| servers and clients must use the same JSON module.
| :param handle_sigint: Set to ``True`` to automatically handle disconnection
| when the process is interrupted, or to ``False`` to
| leave interrupt handling to the calling application.
| Interrupt handling can only be enabled when the
| client instance is created in the main thread.
|
| The Engine.IO configuration supports the following settings:
|
| :param request_timeout: A timeout in seconds for requests. The default is
| 5 seconds.
| :param http_session: an initialized ``requests.Session`` object to be used
| when sending requests to the server. Use it if you
| need to add special client options such as proxy
| servers, SSL certificates, custom CA bundle, etc.
| :param ssl_verify: ``True`` to verify SSL certificates, or ``False`` to
| skip SSL certificate verification, allowing
| connections to servers with self signed certificates.
| The default is ``True``.
| :param websocket_extra_options: Dictionary containing additional keyword
| arguments passed to
| ``websocket.create_connection()``.
| :param engineio_logger: To enable Engine.IO logging set to ``True`` or pass
| a logger object to use. To disable logging set to
| ``False``. The default is ``False``. Note that
| fatal errors are logged even when
| ``engineio_logger`` is ``False``.
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\socketio\simple_client.py
socketio.tornado
Python Library Documentation: module socketio.tornado in socketio
NAME
socketio.tornado
FUNCTIONS
get_tornado_handler(socketio_server)
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\socketio\tornado.py
socketio.zmq_manager
Python Library Documentation: module socketio.zmq_manager in socketio
NAME
socketio.zmq_manager
CLASSES
socketio.pubsub_manager.PubSubManager(socketio.manager.Manager)
ZmqManager
class ZmqManager(socketio.pubsub_manager.PubSubManager)
| ZmqManager(url='zmq+tcp://localhost:5555+5556', channel='socketio', write_only=False, logger=None, json=None)
|
| zmq based client manager.
|
| NOTE: this zmq implementation should be considered experimental at this
| time. At this time, eventlet is required to use zmq.
|
| This class implements a zmq backend for event sharing across multiple
| processes. To use a zmq backend, initialize the :class:`Server` instance as
| follows::
|
| url = 'zmq+tcp://hostname:port1+port2'
| server = socketio.Server(client_manager=socketio.ZmqManager(url))
|
| :param url: The connection URL for the zmq message broker,
| which will need to be provided and running.
| :param channel: The channel name on which the server sends and receives
| notifications. Must be the same in all the servers.
| :param write_only: If set to ``True``, only initialize to emit events. The
| default of ``False`` initializes the class for emitting
| and receiving. A write-only instance can be used
| independently of the server to emit to clients from an
| external process.
| :param logger: a custom logger to log it. If not given, the server logger
| is used.
| :param json: An alternative JSON module to use for encoding and decoding
| packets. Custom json modules must have ``dumps`` and ``loads``
| functions that are compatible with the standard library
| versions. This setting is only used when ``write_only`` is set
| to ``True``. Otherwise the JSON module configured in the
| server is used.
|
| A zmq message broker must be running for the zmq_manager to work.
| you can write your own or adapt one from the following simple broker
| below::
|
| import zmq
|
| receiver = zmq.Context().socket(zmq.PULL)
| receiver.bind("tcp://*:5555")
|
| publisher = zmq.Context().socket(zmq.PUB)
| publisher.bind("tcp://*:5556")
|
| while True:
| publisher.send(receiver.recv())
|
| Method resolution order:
| ZmqManager
| socketio.pubsub_manager.PubSubManager
| socketio.manager.Manager
| socketio.base_manager.BaseManager
| builtins.object
|
| Methods defined here:
|
| __init__(self, url='zmq+tcp://localhost:5555+5556', channel='socketio', write_only=False, logger=None, json=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| zmq_listen(self)
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| name = 'zmq'
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.pubsub_manager.PubSubManager:
|
| can_disconnect(self, sid, namespace)
|
| close_room(self, room, namespace=None)
| Remove all participants from a room.
|
| disconnect(self, sid, namespace=None, **kwargs)
| Register a client disconnect from a namespace.
|
| emit(self, event, data, namespace=None, room=None, skip_sid=None, callback=None, to=None, **kwargs)
| Emit a message to a single client, a room, or all the clients
| connected to the namespace.
|
| This method takes care or propagating the message to all the servers
| that are connected through the message queue.
|
| The parameters are the same as in :meth:`.Server.emit`.
|
| enter_room(self, sid, namespace, room, eio_sid=None)
| Add a client to a room.
|
| initialize(self)
| Invoked before the first request is received. Subclasses can add
| their initialization code here.
|
| leave_room(self, sid, namespace, room)
| Remove a client from a room.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.manager.Manager:
|
| trigger_callback(self, sid, id, data)
| Invoke an application callback.
|
| ----------------------------------------------------------------------
| Methods inherited from socketio.base_manager.BaseManager:
|
| basic_close_room(self, room, namespace)
|
| basic_disconnect(self, sid, namespace, **kwargs)
|
| basic_enter_room(self, sid, namespace, room, eio_sid=None)
|
| basic_leave_room(self, sid, namespace, room)
|
| connect(self, eio_sid, namespace)
| Register a client connection to a namespace.
|
| eio_sid_from_sid(self, sid, namespace)
|
| get_namespaces(self)
| Return an iterable with the active namespace names.
|
| get_participants(self, namespace, room)
| Return an iterable with the active participants in a room.
|
| Note that in a multi-server scenario this method only returns the
| participants connect to the server in which the method is called. There
| is currently no functionality to assemble a complete list of users
| across multiple servers.
|
| get_rooms(self, sid, namespace)
| Return the rooms a client is in.
|
| is_connected(self, sid, namespace)
|
| pre_disconnect(self, sid, namespace)
| Put the client in the to-be-disconnected list.
|
| This allows the client data structures to be present while the
| disconnect handler is invoked, but still recognize the fact that the
| client is soon going away.
|
| set_server(self, server)
|
| sid_from_eio_sid(self, eio_sid, namespace)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketio.base_manager.BaseManager:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\socketio\zmq_manager.py