WEBSOCKET.CONNECT
This is a premium feature.
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, Target])
Arguments
Name | Description |
---|---|
URL | Producer to use for publishing. |
Options | Optional. JSON with connection options. Common options include "auth": "username:password" and "headers": { "HeaderName": "HeaderValue"} . |
Target | Optional. INBOX(), OUTBOX("MsgID") or a cell range where the incoming WebSocket messages will be placed. |
Return Value
WebSocket Connection, if no error.
Examples
Function | Result | Comment |
---|---|---|
=WEBSOCKET.CONNECT("ws://www.example.org",, INBOX("S2")) | WebSocket Connection | Incoming WebSocket messages are placed in the Inbox of the Streamsheet "S2" |