I am designing a system using TD to be run continuously. It receives messages from a socket connection real time.
I want to handle potential errors, but I can’t seem to find a way to check if there is an ongoing connection.
Also how can I check that the sent errors from the callbacks?
I thought about setting a connected boolean variable and make it true when connected and false when disconnected and make the socket attempt connecting while the variable is false but what is the appropriate way to do a “while loop” in TD, since there’s no main method?
The WebSocket DAT prints status and error messages to the TouchDesigner text console. The text console can be enabled by setting the environment variable TOUCH_TEXT_CONSOLE=1 (see: Variables - Derivative). The text console will open the next time TouchDesigner is launched.
You could check the connection state from the Info DAT, and use an Execute DAT on End Frame to attempt your reconnect, or similarly you could use a Timer CHOP if you want to have more control on how much time it should wait for before reconnecting.
In the Palette, you can see the WebRTC → Signaling Client which implements exactly this idea, in relation to the WebRTC → Signaling Server.