I’m trying to make a component to receive data from a web socket. The code of the current version is very simple and it actually works, but in a strange way; so I’d be glad for any insights on its behavior.
The component has a text input parameter for the url (as an item), and a text output, also as a single string.
It uses the WebSocketSharp library to connect and manage the stream.
This is the code responsible for the connection and data output:
WebSocket ws = new WebSocket(@url); ws.Connect(); ws.OnMessage += (sender3, e3) => DA.SetData(0, e3.Data);
And here is a larger part of the component code: https://pastebin.com/W21fshJJ
The main issue is that although the data does change in the output parameter when receiving new messages from the web socket, the solution itself isn’t recomputed, so other components do not receive an updated data.
I was able to solve this by adding a “Data” component connected to the output of this component, and refreshing it with a timer every second or so. But I suspect there should be a better solution.
The other problem is that the output data is not a single item, as it’s supposed to be, but a tree with two branches: first branch with a single item, and the second branch with the text received from the web socket.
The second weird solution was to disable the component after it has connected to the web socket stream - this way it keeps receiving messages, and the output of the component is a single string.
Here is an example of how it looks in GH:
So, the component does work, and can already be useful, but I’d be glad to avoid awkward solutions to these two issues.