class WebSocketServer(object):
WebSocket Server implementation.
| Method | add |
Add a new connection to the list of connections. |
| Method | associate |
Associate a connection with an originator. |
| Method | close |
Close a connection for an originator. |
| Method | configure |
Configure the WebSocket server. |
| Method | dissociate |
Dissociate a connection from an originator. |
| Method | handle |
Handle a new incoming WebSocket connection. This connection stays open until the client closes it, or the server is stopped. |
| Method | increment |
Increment the counter for a connection. |
| Method | init |
Initialization of the WebSocket Server. |
| Method | pause |
Stop handling requests. |
| Method | receive |
Receive loop for the WebSocket server. This is the main entry point for handling a received message, whether the connection was initiated by the server or the client. |
| Method | remove |
Remove a connection from the list of connections. Also remove the association between the connection and the originator. |
| Method | run |
Initialize and run the WebSocket server as a BackgroundWorker/Actor. |
| Method | send |
Send a request to another WebSocket server. |
| Method | shutdown |
Shutdown the WebSocket server. |
| Method | unpause |
Continue handling requests. |
| Method | validate |
Validate the WebSocket server configuration. |
| Class Variable | __slots__ |
Define slots for instance variables. |
| Class Variable | request |
Injected RequestManager instance. |
| Class Variable | security |
Injected SecurityManager instance. |
| Instance Variable | actor |
The actor for running the synchronous WebSocket server in the background. |
| Instance Variable | associated |
The list of currently handled WebSocket connections, associated with an originator. |
| Instance Variable | connection |
A counter for each opened WS connection opened by the CSE. |
| Instance Variable | is |
Flag whether the server is currently paused. Requests are not handled when the server is paused. |
| Instance Variable | operation |
Events for the different operations. |
| Instance Variable | websocket |
The WebSocket server object. |
| Instance Variable | ws |
The list of currently handled WebSocket connections. |
| Method | _check |
Check if the server is running. If not, send an error message to the client. |
| Method | _config |
Callback for the configUpdate event. |
| Method | _get |
Get the target name for sending a WebSocket request. |
| Method | _handle |
Handle the authentication of a new connection. |
| Method | _handle |
Callback and handler for the deleteResource event. |
| Method | _handle |
Handle a received message. This is the main entry point for handling a received message, whether the message is a request or a response. |
| Method | _run |
WebSocket server main loop. |
| Method | _stop |
Stop the WebSocket server. |
Add a new connection to the list of connections.
| Parameters | |
websocket:WSConnection | The WebSocket connection. |
csebool | Undocumented |
Associate a connection with an originator.
If the originator is already associated with another connection then that connection is closed.
| Parameters | |
websocket:WSConnection | The WebSocket connection. |
originator:str | The originator. |
Configure the WebSocket server.
| Parameters | |
config:Configuration | The configuration object to update with the WebSocket server configuration. |
Dissociate a connection from an originator.
| Parameters | |
originator:str | The originator to dissociate. |
| Returns | |
bool | True if the originator was associated with a connection, False otherwise. |
Handle a new incoming WebSocket connection. This connection stays open until the client closes it, or the server is stopped.
Note
This method is not called for connections initiated by the server.
| Parameters | |
websocket:ServerConnection | The WebSocket connection. |
WSConnection, wsOriginator: str, ct: ContentSerializationType, authResult: AuthorizationResult):
¶
Receive loop for the WebSocket server. This is the main entry point for handling a received message, whether the connection was initiated by the server or the client.
| Parameters | |
websocket:WSConnection | The WebSocket connection. |
wsstr | The originator of the connection. |
ct:ContentSerializationType | The content type. |
authAuthorizationResult | The result of the request authentication. |
Remove a connection from the list of connections. Also remove the association between the connection and the originator.
| Parameters | |
websocket:WSConnection | The WebSocket connection. |
originator:str | The originator. |
Send a request to another WebSocket server.
| Parameters | |
request:CSERequest | The request to send. |
url:str | The URL to send the request to. |
ignorebool | Flag whether to ignore the response. |
| Returns | |
Result | The result object of the request. |
Validate the WebSocket server configuration.
| Parameters | |
config:Configuration | The configuration object to validate. |
Check if the server is running. If not, send an error message to the client.
| Returns | |
bool | True if the server is running, False otherwise. |
Callback for the configUpdate event.
| Parameters | |
eventEventData | The event data containing the name of the updated configuration setting and its new value. |
Get the target name for sending a WebSocket request.
| Parameters | |
target:str | The target to send the request to. |
| Returns | |
str | The target for sending the request. |
Handle the authentication of a new connection.
| Parameters | |
websocket:WSConnection | The WebSocket connection. |
| Returns | |
AuthorizationResult | Eneumeration value of the result of the authentication. |
Callback and handler for the deleteResource event.
In case of an AE deletion, the associated WS connection is dissociated, but left open.
| Parameters | |
eventEventData | The event data containing the deleted resource. |
WSConnection, message: str | bytes, wsOriginator: str, contentType: ContentSerializationType, authResult: AuthorizationResult):
¶
Handle a received message. This is the main entry point for handling a received message, whether the message is a request or a response.
| Parameters | |
websocket:WSConnection | The WebSocket connection. |
message:str | bytes | The received message. |
wsstr | The originator of the connection. |
contentContentSerializationType | The content type. |
authAuthorizationResult | The result of the request authentication. |