Published
Edited
Aug 30, 2021
1 star
Insert cell
md`# Websocket client usage`
Insert cell
Insert cell
exampleSocket = new WebSocket("wss://yourserverurl.com", ["protocolOne", "protocolTwo"])
// ws for standard, wss for TLS
// look at doc for protocols, you probably don't need them
Insert cell
Insert cell
exampleSocket.onmessage = function (event) {
mutable data = event.data
}
Insert cell
Insert cell
exampleSocket.onopen = function (event) {
exampleSocket.send(JSON.stringify({action: 'connect'})); // must be a string/arraybuffer/blob
}
Insert cell
// Uncomment and run below once a connection is established
// exampleSocket.send(JSON.stringify({action: 'message', name: 'testing'}))
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more