circuits.web.websockets.client module

class circuits.web.websockets.client.WebSocketClient(url, channel='wsclient', wschannel='ws', headers=None)

Bases: circuits.core.components.BaseComponent

An RFC 6455 compliant WebSocket client component. Upon receiving a circuits.web.client.Connect event, the component tries to establish the connection to the server in a two stage process. First, a circuits.net.events.connect event is sent to a child TCPClient. When the TCP connection has been established, the HTTP request for opening the WebSocket is sent to the server. A failure in this setup process is signaled by raising an NotConnected exception.

When the server accepts the request, the WebSocket connection is established and can be used very much like an ordinary socket by handling read events on and sending write events to the channel specified as the wschannel parameter of the constructor. Firing a close event on that channel closes the connection in an orderly fashion (i.e. as specified by the WebSocket protocol).

Parameters:
  • url – the URL to connect to.
  • channel – the channel used by this component
  • wschannel – the channel used for the actual WebSocket communication (read, write, close events)
  • headers – additional headers to be passed with the WebSocket setup HTTP request
channel = 'wsclient'
close()
connected