WEBSOCKET.CONNECT
The WebSocket API is an advanced technology that makes it possible to open a two-way interactive communication session between the user(client) and the server. With this API, you can send messages to a server and receive event-driven responses without having to poll the server for a reply.
This functions opens a WebSocket Connection using the given URL. Whenever WEBSOCKET.CONNECT is evaluated a new connection is created if:
- the connection is not currently active or
- the connection arguments (URL and/or Options) changed.
If the connection is active and the arguments are unchanged since the last evaluation the active connection is returned and no new connection is created.
The recommended way to open a WebSocket connection (and keep it open) is to place the WEBSOCKET.CONNECT function in a Streamsheet running with the calculation mode "On Time" and an interval of e.g. 5 seconds. This way the connection is verified every 5 seconds and recreated if necessary.
Syntax
=WEBSOCKET.CONNECT(URL, [Options])
Arguments
Name | Type | Description |
---|---|---|
URL | String | Producer to use for publishing. |
Options (optional) | JSON | JSON with connection options. Common options include "auth": "username:password" and "headers": { "HeaderName": "HeaderValue"}. |
Return
Type | Description |
---|---|
String | WebSocket Connection, if no error. |
Examples
Formula | Result | Comment |
---|---|---|
| WebSocket Connection | Incoming WebSocket messages are placed in the Inbox of the Streamsheet "S2" |