circuits.web.websockets.dispatcher module

class circuits.web.websockets.dispatcher.WebSocketsDispatcher(*args, **kwargs)

Bases: BaseComponent

This class implements an RFC 6455 compliant WebSockets dispatcher that handles the WebSockets handshake and upgrades the connection.

The dispatcher listens on its channel for Request events and tries to match them with a given path. Upon a match, the request is checked for the proper Opening Handshake information. If successful, the dispatcher confirms the establishment of the connection to the client. Any subsequent data from the client is handled as a WebSocket data frame, decoded and fired as a Read event on the wschannel passed to the constructor. The data from write events on that channel is encoded as data frames and forwarded to the client.

Firing a Close event on the wschannel closes the connection in an orderly fashion (i.e. as specified by the WebSocket protocol).

Parameters
  • path – the path to handle. Requests that start with this path are considered to be WebSocket Opening Handshakes.

  • wschannel – the channel on which read events from the client will be delivered and where write events to the client will be sent to.

channel = 'web'
select_subprotocol(subprotocols)