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])

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(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()

Called when a new client connection is established

on_close()

Called when the client connection is closed

on_message(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()

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(rejectMsg)
open()
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(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(msg)

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

callback(client, message)

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

get_response(callId, timeout=None)

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

close_pending_requests()

Close requests and signal any threads waiting for responses.

pruneCallbacks()

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