From 3529c203ce9db01254ec7a5d70aa6c6e37da8d77 Mon Sep 17 00:00:00 2001 From: "sumit shinde ( Roni )" <110285294+sumitshinde-84@users.noreply.github.com> Date: Fri, 12 Apr 2024 15:26:07 +0530 Subject: [PATCH] Update websocket-use-case.md --- .../core-nodes/websocket-use-case.md | 47 +++++++++++++++---- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/src/_includes/core-nodes/websocket-use-case.md b/src/_includes/core-nodes/websocket-use-case.md index b0ffd0bd34..8acfd27f06 100644 --- a/src/_includes/core-nodes/websocket-use-case.md +++ b/src/_includes/core-nodes/websocket-use-case.md @@ -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 @@ -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"}] -``` \ No newline at end of file +```