Middlewares

class socketio.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.

Parameters:
  • socketio_app – The Socket.IO server. Must be an instance of the socketio.Server class.

  • wsgi_app – The WSGI app that receives all other traffic.

  • static_files – A dictionary with static file mapping rules. See the documentation for details on this argument.

  • 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)
class socketio.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.

Parameters:
  • socketio_server – The Socket.IO server. Must be an instance of the socketio.AsyncServer class.

  • static_files – A dictionary with static file mapping rules. See the documentation for details on this argument.

  • other_asgi_app – A separate ASGI app that receives all other traffic.

  • 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.

  • on_startup – function to be called on application startup; can be coroutine

  • 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)
class socketio.Middleware(socketio_app, wsgi_app=None, socketio_path='socket.io')

This class has been renamed to WSGIApp and is now deprecated.