Module Contents¶
Classes¶
Adapter class for Twisted WebSocket client and server protocols. |
|
Base class for Twisted-based WebSocket server protocols. |
|
Base class for Twisted-based WebSocket client protocols. |
|
Adapter class for Twisted-based WebSocket client and server factories. |
|
Base class for Twisted-based WebSocket server factories. |
|
Base class for Twisted-based WebSocket client factories. |
|
An adapter for stream-based transport over WebSocket. |
|
Server protocol for stream-based transport over WebSocket. |
|
Client protocol for stream-based transport over WebSocket. |
|
Wrapping server factory for stream-based transport over WebSocket. |
|
Wrapping client factory for stream-based transport over WebSocket. |
|
Twisted-based WAMP-over-WebSocket server protocol. |
|
Twisted-based WAMP-over-WebSocket server protocol factory. |
|
Twisted-based WAMP-over-WebSocket client protocol. |
|
Twisted-based WAMP-over-WebSocket client protocol factory. |
Functions¶
|
|
|
Establish WebSocket connection to a server. The connection parameters like target |
|
Listen for incoming WebSocket connections from clients. The connection parameters like |
- autobahn.twisted.websocket.create_client_agent(reactor)[source]¶
- Returns
an instance implementing IWebSocketClientAgent
- class autobahn.twisted.websocket.WebSocketAdapterProtocol[source]¶
Bases:
twisted.internet.protocol.Protocol
Adapter class for Twisted WebSocket client and server protocols.
Called from Twisted:
autobahn.twisted.websocket.WebSocketAdapterProtocol.connectionMade()
autobahn.twisted.websocket.WebSocketAdapterProtocol.connectionLost()
autobahn.twisted.websocket.WebSocketAdapterProtocol.dataReceived()
Called from Network-independent Code (WebSocket implementation):
autobahn.twisted.websocket.WebSocketAdapterProtocol._onOpen()
autobahn.twisted.websocket.WebSocketAdapterProtocol._onMessageBegin()
autobahn.twisted.websocket.WebSocketAdapterProtocol._onMessageFrameData()
autobahn.twisted.websocket.WebSocketAdapterProtocol._onMessageFrameEnd()
autobahn.twisted.websocket.WebSocketAdapterProtocol._onMessageEnd()
autobahn.twisted.websocket.WebSocketAdapterProtocol._onMessage()
autobahn.twisted.websocket.WebSocketAdapterProtocol._onPing()
autobahn.twisted.websocket.WebSocketAdapterProtocol._onPong()
autobahn.twisted.websocket.WebSocketAdapterProtocol._onClose()
FIXME:
autobahn.twisted.websocket.WebSocketAdapterProtocol._closeConnection()
autobahn.twisted.websocket.WebSocketAdapterProtocol._create_transport_details()
autobahn.twisted.websocket.WebSocketAdapterProtocol.registerProducer()
autobahn.twisted.websocket.WebSocketAdapterProtocol.unregisterProducer()
- log¶
- peer :Optional[str]¶
- is_server :Optional[bool]¶
- connectionMade()[source]¶
Called when a connection is made.
This may be considered the initializer of the protocol, because it is called when the connection is completed. For clients, this is called once the connection to the server has been established; for servers, this is called after an accept() call stops blocking and a socket has been received. If you need to send any greeting or initial message, do it here.
- connectionLost(reason: twisted.python.failure.Failure = connectionDone)[source]¶
Called when the connection is shut down.
Clear any circular references here, and any external references to this Protocol. The connection has been closed.
@type reason: L{twisted.python.failure.Failure}
- dataReceived(data: bytes)[source]¶
Called whenever data is received.
Use this method to translate to a higher-level message. Usually, some callback will be made upon the receipt of each complete protocol message.
- @param data: a string of indeterminate length. Please keep in mind
that you will probably need to buffer some data, as partial (or multiple) protocol messages may be received! I recommend that unit tests for protocols call through to this method with differing chunk sizes, down to one byte at a time.
- class autobahn.twisted.websocket.WebSocketServerProtocol[source]¶
Bases:
WebSocketAdapterProtocol
,autobahn.websocket.protocol.WebSocketServerProtocol
Base class for Twisted-based WebSocket server protocols.
Implements
autobahn.websocket.interfaces.IWebSocketChannel
.- log¶
- is_server = True¶
- class autobahn.twisted.websocket.WebSocketClientProtocol[source]¶
Bases:
WebSocketAdapterProtocol
,autobahn.websocket.protocol.WebSocketClientProtocol
Base class for Twisted-based WebSocket client protocols.
Implements
autobahn.websocket.interfaces.IWebSocketChannel
.- log¶
- is_server = False¶
- _onConnect(response: autobahn.websocket.types.ConnectionResponse)[source]¶
- class autobahn.twisted.websocket.WebSocketAdapterFactory[source]¶
Bases:
object
Adapter class for Twisted-based WebSocket client and server factories.
- class autobahn.twisted.websocket.WebSocketServerFactory(*args, **kwargs)[source]¶
Bases:
WebSocketAdapterFactory
,autobahn.websocket.protocol.WebSocketServerFactory
,twisted.internet.protocol.ServerFactory
Base class for Twisted-based WebSocket server factories.
Implements
autobahn.websocket.interfaces.IWebSocketServerChannelFactory
- log¶
- class autobahn.twisted.websocket.WebSocketClientFactory(*args, **kwargs)[source]¶
Bases:
WebSocketAdapterFactory
,autobahn.websocket.protocol.WebSocketClientFactory
,twisted.internet.protocol.ClientFactory
Base class for Twisted-based WebSocket client factories.
Implements
autobahn.websocket.interfaces.IWebSocketClientChannelFactory
- log¶
- class autobahn.twisted.websocket.WrappingWebSocketAdapter[source]¶
Bases:
object
An adapter for stream-based transport over WebSocket.
This follows websockify and should be compatible with that.
It uses WebSocket subprotocol negotiation and supports the following WebSocket subprotocols:
binary
(or a compatible subprotocol)base64
Octets are either transmitted as the payload of WebSocket binary messages when using the
binary
subprotocol (or an alternative binary compatible subprotocol), or encoded with Base64 and then transmitted as the payload of WebSocket text messages when using thebase64
subprotocol.
- class autobahn.twisted.websocket.WrappingWebSocketServerProtocol[source]¶
Bases:
WrappingWebSocketAdapter
,WebSocketServerProtocol
Server protocol for stream-based transport over WebSocket.
- class autobahn.twisted.websocket.WrappingWebSocketClientProtocol[source]¶
Bases:
WrappingWebSocketAdapter
,WebSocketClientProtocol
Client protocol for stream-based transport over WebSocket.
- class autobahn.twisted.websocket.WrappingWebSocketServerFactory(factory, url, reactor=None, enableCompression=True, autoFragmentSize=0, subprotocol=None)[source]¶
Bases:
WebSocketServerFactory
Wrapping server factory for stream-based transport over WebSocket.
- buildProtocol(addr)[source]¶
Create an instance of a subclass of Protocol.
The returned instance will handle input on an incoming server connection, and an attribute “factory” pointing to the creating factory.
Alternatively, L{None} may be returned to immediately close the new connection.
Override this method to alter how Protocol instances get created.
@param addr: an object implementing L{IAddress}
- startFactory()[source]¶
This will be called before I begin listening on a Port or Connector.
It will only be called once, even if the factory is connected to multiple ports.
This can be used to perform ‘unserialization’ tasks that are best put off until things are actually running, such as connecting to a database, opening files, etcetera.
- stopFactory()[source]¶
This will be called before I stop listening on all Ports/Connectors.
This can be overridden to perform ‘shutdown’ tasks such as disconnecting database connections, closing files, etc.
It will be called, for example, before an application shuts down, if it was connected to a port. User code should not call this function directly.
- class autobahn.twisted.websocket.WrappingWebSocketClientFactory(factory, url, reactor=None, enableCompression=True, autoFragmentSize=0, subprotocol=None)[source]¶
Bases:
WebSocketClientFactory
Wrapping client factory for stream-based transport over WebSocket.
- buildProtocol(addr)[source]¶
Create an instance of a subclass of Protocol.
The returned instance will handle input on an incoming server connection, and an attribute “factory” pointing to the creating factory.
Alternatively, L{None} may be returned to immediately close the new connection.
Override this method to alter how Protocol instances get created.
@param addr: an object implementing L{IAddress}
- autobahn.twisted.websocket.connectWS(factory, contextFactory=None, timeout=30, bindAddress=None)[source]¶
Establish WebSocket connection to a server. The connection parameters like target host, port, resource and others are provided via the factory.
- Parameters
factory (An
autobahn.websocket.WebSocketClientFactory
instance.) – The WebSocket protocol factory to be used for creating client protocol instances.contextFactory (A twisted.internet.ssl.ClientContextFactory instance.) – SSL context factory, required for secure WebSocket connections (“wss”).
timeout (int) – Number of seconds to wait before assuming the connection has failed.
bindAddress (tuple) – A (host, port) tuple of local address to bind to, or None.
- Returns
The connector.
- Return type
An object which implements twisted.interface.IConnector.
- autobahn.twisted.websocket.listenWS(factory, contextFactory=None, backlog=50, interface='')[source]¶
Listen for incoming WebSocket connections from clients. The connection parameters like listening port and others are provided via the factory.
- Parameters
factory (An
autobahn.websocket.WebSocketServerFactory
instance.) – The WebSocket protocol factory to be used for creating server protocol instances.contextFactory (A twisted.internet.ssl.ContextFactory.) – SSL context factory, required for secure WebSocket connections (“wss”).
backlog (int) – Size of the listen queue.
interface (str) – The interface (derived from hostname given) to bind to, defaults to ‘’ (all).
- Returns
The listening port.
- Return type
An object that implements twisted.interface.IListeningPort.
- class autobahn.twisted.websocket.WampWebSocketServerProtocol[source]¶
Bases:
autobahn.wamp.websocket.WampWebSocketServerProtocol
,WebSocketServerProtocol
Twisted-based WAMP-over-WebSocket server protocol.
Implements:
- class autobahn.twisted.websocket.WampWebSocketServerFactory(factory, *args, **kwargs)[source]¶
Bases:
autobahn.wamp.websocket.WampWebSocketServerFactory
,WebSocketServerFactory
Twisted-based WAMP-over-WebSocket server protocol factory.
- protocol¶
- class autobahn.twisted.websocket.WampWebSocketClientProtocol[source]¶
Bases:
autobahn.wamp.websocket.WampWebSocketClientProtocol
,WebSocketClientProtocol
Twisted-based WAMP-over-WebSocket client protocol.
Implements:
- class autobahn.twisted.websocket.WampWebSocketClientFactory(factory, *args, **kwargs)[source]¶
Bases:
autobahn.wamp.websocket.WampWebSocketClientFactory
,WebSocketClientFactory
Twisted-based WAMP-over-WebSocket client protocol factory.
- protocol¶