Skip to main content
Version: Streamsheets 3.0

WEBSOCKET.CONNECT

Premium

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])

Arguments

NameTypeDescription
URLStringProducer to use for publishing.
Options (optional)JSONJSON with connection options. Common options include "auth": "username:password" and "headers": { "HeaderName": "HeaderValue"}.

Return

TypeDescription
StringWebSocket Connection, if no error.

Examples

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