Skip to main content
Version: Streamsheets 2.5

WEBSOCKET.CONNECT

star 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:

  1. the connection is not currently active or
  2. 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

NameDescription
URLProducer to use for publishing.
OptionsOptional. JSON with connection options. Common options include "auth": "username:password" and "headers": { "HeaderName": "HeaderValue"}.
TargetOptional. INBOX(), OUTBOX("MsgID") or a cell range where the incoming WebSocket messages will be placed.

Return Value

WebSocket Connection, if no error.

Examples

FunctionResultComment
=WEBSOCKET.CONNECT("ws://www.example.org",, INBOX("S2"))WebSocket ConnectionIncoming WebSocket messages are placed in the Inbox of the Streamsheet "S2"