circuits.web.websockets.client module¶
- class circuits.web.websockets.client.WebSocketClient(*args, **kwargs)¶
Bases:
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, acircuits.net.events.connect
event is sent to a childTCPClient
. 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 anNotConnected
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 sendingwrite
events to the channel specified as thewschannel
parameter of the constructor. Firing aclose
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()¶
- property connected¶