Accessor: dashboard/RoutingWebSocketServer

dashboard/RoutingWebSocketServer

This accessor is an extension of the WebSocketServer, which wraps the functionality of the base class with the additional feature of tracking the ID attribute of JSON messages received from the network and automatically directing messages outgoing from the swarmlet with corresponding message ID parameters for the matching socketID number.

This accessor assumes messages sent over the web socket have the form of stringified JSON, where the JSON has a string attribute named "ID" (a message ID). When a message is received from the network, this accessor updates an internal mapping of message IDs to socketIDs to reflect the socket on which the message ID was received. When a JSON message is received on this accessor's routingSend input, it will be stringified and sent over the web socket to the socketID matching the outgoing message's ID attribute. Note: Outgoing messages without an ID attribute or without an established mapping to a socketID will be treated as errors and discarded!

To use this mode of communication, outgoing messages from the swarmlet should be directed to the "routingSend" input instead of the base class's "toSend" input.

Refer to the documentation of WebSocketServer for a more complete description of the extended accessor.

Version:
  • $$Id$$
Author:
  • Hokeun Kim, Edward Lee
Source:
Inputs:
Name Type Description
routingSend JSON data with an 'ID' attribute to be stringified and sent over the open socket upon which this accessor has prior received a network message with a matching 'ID' attribute.
toSend The data to be sent to open sockets. If this is an object with 'socketID' field and a 'message' field, then send the value of the message field to the socket identified by the socketID field. If the input has any other form, then the message is broadcast to all open socket connections.
Outputs:
Name Type Description
listening int When the server is listening for connections, this output will produce the port number that the server is listening on
connection An output produced when a connection opens or closes. The output is an object with two fields, a 'socketID', which is a unique ID for this client connection, and a 'status' field, which is the string 'open' or 'closed'.
received A message received a client in the form of an object with two fields, a 'socketID', which is a unique ID for this client connection, and a 'message' field, which is the message received from the client.
Parameters:
Name Type Description
hostInterface string The IP address or domain name of the network interface to listen to.
port int The port to listen to for connections.
pfxKeyCertPassword string If sslTls is set to true, then this option needs to specify the password for the pfx key-cert file specified by pfxKeyCertPath.
pfxKeyCertPath string If sslTls is set to true, then this option needs to specify the fully qualified filename for the file that stores the private key and certificate that this server will use to identify itself. This path can be any of those understood by the Ptolemy host, e.g. paths beginning with $CLASSPATH/.
receiveType string The MIME type for incoming messages, which defaults to 'text/plain'.
sendType string The MIME type for outgoing messages, which defaults to 'text/plain'.
sslTls boolean Whether SSL/TLS is enabled. This defaults to false.

Methods

(static) initialize()

Adds an input handler on routingSend that converts the input into a message delivered to the toSend input of the superclass.

Source:

(static) setup()

Sets up the accessor by defining inputs and outputs.

Source: