How to disconnect a websocket programmatically?

Well,

normally, one wants a "websocket out" node to connect to a server in order to send a message and a "websocket in" node to connect as well in order to receive the response.

But, how can one programmatically shut down that connection as soon as all messages have been sent and all responses received?

Changing the flow and redeploying it is not an option - the disconnect shut be done by the flow itself.

Is there a solution?

the point of websocket is to stay open .. otherwise you use http requests :wink:

there was a recent forum thread asking the same but i dont think there is a way to close the connection with the existing nodes.

Here is that post with a code alternative

1 Like

Thank you very much for your response!

Let me quote MDN:

The WebSocket.close() method closes the WebSocket connection or connection attempt, if any. If the connection is already CLOSED , this method does nothing.

There is much between single HTTP request-response messages and "everlasting" WebSocket connections but it might not be easy to map features such as

  • the connection event on the server side,
  • WebSocket.bufferedAmount and
  • WebSocket.close()

to nodes which are easy to be used...

The close method is for clients.

For a simple websocket server both the client and the server have the same rights to close the connection. So it looks like you can issue a .close method from the server.

WebSocket (javascript.info)

That's a really interesting reference! Thank you!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.