Skip to content

Commit

Permalink
Merge pull request #1925 from FlowFuse/sumitshinde-84-patch-1
Browse files Browse the repository at this point in the history
Update websocket-use-case.md
  • Loading branch information
ZJvandeWeg authored Apr 12, 2024
2 parents f12cabe + 3529c20 commit 7462d13
Showing 1 changed file with 38 additions and 9 deletions.
47 changes: 38 additions & 9 deletions src/_includes/core-nodes/websocket-use-case.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,47 @@
## What is are WebSocket nodes used for in Node-RED
## What are WebSocket nodes used for in Node-RED

Node-RED comes with 2 WebSocket nodes, both of which can work in 2 modes
Node-RED provides two WebSocket nodes that serve distinct purposes and can operate in two modes.

### Listen on
### Listen On

In this mode Node-RED will create a WebSocket server and allow remote clients to connect.
In this mode, Node-RED functions as a WebSocket server, enabling remote clients to establish connections.

The `WebSocket-in` node will receive messages sent from the remote client and the `WebSocket-out` allows the flow to send messages either to a specific connected client or to broadcast to all connected clients
- The `WebSocket-in` node is responsible for receiving messages sent from remote clients.
- The `WebSocket-out` node facilitates the flow to send messages either to a specific connected client or to broadcast messages to all connected clients.

### Connect to
### Connect To

In this mode Node-RED connects out to a remote WebSocket server.
In this mode, Node-RED acts as a client, establishing connections with remote WebSocket servers.

The `WebSocket-in` node receives messages sent to Node-RED and the `WebSocket-out` node allows the flow to send messages to the remote server.
- The `WebSocket-in` node receives messages sent from the remote WebSocket server to Node-RED.
- The `WebSocket-out` node allows the flow to send messages to the remote server.

## WebSocket node configuration

### Path

When you use the WebSocket node in "Listen on" mode, you'll have to specify the path or endpoint to which remote clients will establish a connection.

### Send/Receive

- Payload: This option sends or receives only the `msg.payload` as data over the WebSocket connection. It excludes any additional `msg` properties.
- Entire Message: When enabled, this option allows the entire message object, including payload, and other properties to be sent or received as a JSON formatted string.

### URL

When you use the WebSocket node in "Connect to" mode, you'll have to specify the connection URL that should use `ws://` or `wss://` scheme and point to an existing WebSocket listener.

### Subprotocol

This option allows you to specify a particular WebSocket subprotocol to use during the connection handshake.

For example, if a WebSocket server requires the use of the "mqtt" subprotocol, you would configure the WebSocket node's "Subprotocol" option to "mqtt" to ensure that the WebSocket handshake includes the MQTT protocol, enabling proper communication between Node-RED and the WebSocket server.

### Send heartbeat

Enabling this option allows specifying the time interval in seconds for sending periodic ping messages from the client to the server to maintain the connection. The server responds with a pong message to confirm the connection status.

This helps prevent the connection from being closed due to inactivity or network issues.

## Examples

Expand All @@ -25,4 +54,4 @@ and the other connecting to that server and sending and receiving messages.

```json
[{"id":"43294be738b7699a","type":"tab","label":"WebSockets","disabled":false,"info":"","env":[]},{"id":"e788dbc44428f6b7","type":"websocket in","z":"43294be738b7699a","name":"","server":"","client":"4db78eb653d6d50d","x":290,"y":240,"wires":[["d86baf93795dbb2d"]]},{"id":"8c702971b0292f9b","type":"websocket out","z":"43294be738b7699a","name":"","server":"","client":"4db78eb653d6d50d","x":510,"y":180,"wires":[]},{"id":"dda81a976ccf2a2b","type":"inject","z":"43294be738b7699a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":180,"wires":[["8c702971b0292f9b"]]},{"id":"d86baf93795dbb2d","type":"debug","z":"43294be738b7699a","name":"debug 5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":580,"y":240,"wires":[]},{"id":"d36a13e17814e375","type":"websocket in","z":"43294be738b7699a","name":"","server":"542f751e15337c46","client":"","x":230,"y":320,"wires":[["1660b4da46db22ad"]]},{"id":"1660b4da46db22ad","type":"websocket out","z":"43294be738b7699a","name":"","server":"542f751e15337c46","client":"","x":560,"y":320,"wires":[]},{"id":"4db78eb653d6d50d","type":"websocket-client","path":"ws://localhost:1880/ws/echo","tls":"","wholemsg":"false","hb":"0","subprotocol":""},{"id":"542f751e15337c46","type":"websocket-listener","path":"/ws/echo","wholemsg":"false"}]
```
```

0 comments on commit 7462d13

Please sign in to comment.