circuits.protocols.websocket module

class circuits.protocols.websocket.WebSocketCodec(*args, **kwargs)

Bases: BaseComponent

WebSocket Protocol

Implements the Data Framing protocol for WebSocket.

This component is used in conjunction with a parent component that receives Read events on its channel. When created (after a successful WebSocket setup handshake), the codec registers a handler on the parent’s channel that filters out these Read events for a given socket (if used in a server) or all Read events (if used in a client). The data is decoded and the contained payload is emitted as Read events on the codec’s channel.

The data from write events sent to the codec’s channel (with socket argument if used in a server) is encoded according to the WebSocket Data Framing protocol. The encoded data is then forwarded as write events on the parents channel.

Creates a new codec.

Parameters

sock – the socket used in Read and write events (if used in a server, else None)

channel = 'ws'