WebSocket Message
The WebSocket trigger receives messages over TCP from a WebSocket-supported client, which can include the WebSocketSender transformer in an FME workspace, and the following Java or HTML5 web browsers:
- Internet Explorer 10+
- Firefox 11+
- Chrome 16+
- Safari 6+
- Opera 12.10+
The WebSocket trigger has two output ports. The success port (✔) can send a message if the trigger receives it successfully. The failure port (x) can send a message if the trigger fails to communicate with the client.
WebSocket Communication Channels
The WebSocket Server is located on the FME Server Core. By default, FME Server uses the following channels for WebSocket communication:
- Port: 7078
- URI: ws://<hostname>:7078/websocket
To configure the WebSocket server for SSL communication, see Configuring for HTTPS.
Parameters
Note: See also Working with Parameters in Automations Workflows.
Tip: To test that your parameters work as expected, click Validate.
- Target URL: This field is pre-populated with the URL of the FME Server WebSocket Server (included with your FME Server installation). Alternatively, you can connect to a different WebSocket server.
- Stream ID: Specify the Stream ID for the trigger. The Stream ID allows the WebSocket server to identify messages and connect them to the trigger.
Output Keys
See Also
Key | Description |
---|---|
time | Event time |
source | Event type |
error.type |
(Failure port only) Error type:
|
error.message | (Failure port only) Error message |
message | (Success port only) Message content |
Messaging Protocol
The WebSocket server must open messages before sending them. To open messages, the following schema is used:
Note: JSON is used for all messaging
{
"ws_op" : "open",
"ws_stream_ids" : ["<streamid1>", "<streamid2>", "<streamid3>", ...]
}
Once a message is opened, a connection is established, using the Stream ID to identify the message. The WebSocket server then relays messages using this schema:
{
"ws_op" : "send",
"ws_msg" : "msg"
}
The WebSocket server supports sending multiple messages after a stream is opened.
After sending messages, it is a good practice to request that the WebSocket server close the message stream. However, if a message is not explicitly closed, the WebSocket server closes it automatically.
{
"ws_op": "close"
}
Keys:
- ws_op: Defines the WebSocket operation. If you want the WebSocket server to open messages, specify "open". To send messages, specify "send". To close a message stream, specify "close".
- ws_stream_ids: Identifies one or more message streams so the WebSocket server can associate them with the Source.
For example, consider the following series of messages from an HTML5 client to your WebSocket Server:
{
"ws_op" : "open",
"ws_stream_ids" : "send-stream",
}
{
"ws_op" : "send",
"ws_msg" : "Hello World"
}
{
"ws_op" : "close"
}
After the WebSocket server opens the "send-stream" message stream, it is sent to any triggers created on that stream. The WebSocket server then closes the stream.
You can send messages containing information about all channels that are currently opened on the FME Server WebSocket server. This information can be useful for administering and troubleshooting WebSocket communications.
To get the number of open WebSocket channels, by Stream ID
{
"ws_op" : "admin",
"ws_msg" : "getnumchannels()"
}
Corresponding response object:
{
"numchannels" : "<number_of_channels>",
"streams":[
{
"stream" : "message_stream_id",
"numchannels" : "<number_of_channels_open_on_this_stream>"
},
<...>
{
]
}
To get connection information about each open WebSocket channel
{
"ws_op" : "admin",
"ws_msg" : "getchannelinfo()"
}
Corresponding response object:
{
"numchannels" : "<number_of_channels>",
"channels" :[
{
"port" : "<channel_port_number>",
"stream" : "message_stream_id",
"host" : "channel_host_ip_address",
"writable" : "<channel_is_writable_true_or_false>"
},
<...>
{
]
}
See Also