rtCommon.webSocketHandlers

This module provides classes for handling web socket communication in the web interface.

Module Contents

Classes

websocketState

A global static class (really a struct) for maintaining connection and callback information.

BaseWebSocketHandler

Generic web socket handler. Estabilishes and maintains a ws connection. Intitialized with

DataWebSocketHandler

Sub-class the base handler in order to clean up any outstanding requests on close.

RejectWebSocketHandler

A web socket handler that rejects connections on the web socket and returns a

RequestHandler

Class for handling remote requests (such with a remote DataInterface). Each data requests is

Functions

sendWebSocketMessage(wsName, msg, conn=None)

Send messages from the web server to all clients connected on the specified wsName socket.

closeAllConnections()

defaultWebsocketCallback(client, message)

class rtCommon.webSocketHandlers.websocketState

A global static class (really a struct) for maintaining connection and callback information.

wsConnLock
wsConnectionLists
wsCallbacks
class rtCommon.webSocketHandlers.BaseWebSocketHandler

Bases: tornado.websocket.WebSocketHandler

Generic web socket handler. Estabilishes and maintains a ws connection. Intitialized with

a callback function that gets called when messages are received on this socket instance.

initialize(self, name, callback=None, connNotify=None)

initialize method is called by Tornado with args provided to the addHandler call

Parameters
  • name – the websocket endpoint name, such as wsData

  • callback – the handler function to call whenever a client message is received over the connection.

  • connNotify – the function to call when a connection is opened or closed.

open(self)

Called when a new client connection is established

on_close(self)

Called when the client connection is closed

on_message(self, message)

Called when a message is received from a client connection

class rtCommon.webSocketHandlers.DataWebSocketHandler

Bases: BaseWebSocketHandler

Sub-class the base handler in order to clean up any outstanding requests on close.

on_close(self)

Called when the client connection is closed

class rtCommon.webSocketHandlers.RejectWebSocketHandler

Bases: tornado.websocket.WebSocketHandler

A web socket handler that rejects connections on the web socket and returns a pre-configured error with the rejection reason.

initialize(self, rejectMsg)
open(self)
rtCommon.webSocketHandlers.sendWebSocketMessage(wsName, msg, conn=None)

Send messages from the web server to all clients connected on the specified wsName socket.

rtCommon.webSocketHandlers.closeAllConnections()
rtCommon.webSocketHandlers.defaultWebsocketCallback(client, message)
class rtCommon.webSocketHandlers.RequestHandler(name, ioLoopInst)

Class for handling remote requests (such with a remote DataInterface). Each data requests is given a unique ID and callbacks from the client are matched to the original request and results returned to the corresponding caller.

doRequest(self, msg, timeout=None)

Send a request over the web socket, i.e. to the remote FileWatcher. This is typically the only call that a user of this class would make. It is the highest level call of this class, it uses the other methods to complete the request.

prepare_request(self, msg)

Prepate a request to be sent, including creating a callback structure and unique ID.

callback(self, client, message)

Recieve a callback from the client and match it to the original request that was sent.

get_response(self, callId, timeout=None)

Client calls get_response() to wait for the callback results to be returned.

close_pending_requests(self)

Close requests and signal any threads waiting for responses.

pruneCallbacks(self)

Remove any orphaned callback structures that never got a response back.