ZMQ inside TouchDesigner

Hey, I’m trying to implement ZMQ(only Server), but TD stops responding as soon as I run the script. Did anyone successfully managed to use this protocol inside TD?

Without seeing your code nobody will be able to help you . Most likely you copied some example code with a while loop and some blocking commands

I removed while loop from ZeroMQ python example code. The code is uploaded, thank you for reminding me!
The Feeling Machine.toe (4.7 KB)

So is it working now? I can’t test as I don’t have zeromq installed.

I assume that you can click your Run pulse button on the server and you get data, but you want to automatically receive an update whenever a client sends a message?

No, unfortunately I’m still not receiving any messages on the server side. I thought it might have to do with the fact that I’m re-binding to the server on each Run pulse, but this didn’t solve the problem. (22.7 KB)

I’m sorry, but I can’t help you here without getting deep into zmq myself

Maybe @Ivan has a quick fix/idea?

I don’t think there is quite a quick fix as this is not the easiest task to setup ZMQ in TouchDesigner, although doable.

@kratadata - seeing that you want to setup both a server in TouchDesigner, and a client, I wonder what leads you to pick ZMQ in the first place ? Why not picking a similar protocol that TouchDesigner supports natively like MQTT ? Or a bit different but easy to implement anywhere, WebSocket ?

If you have to stick to ZMQ, you likely will need to thread everything and in the context of TouchDesigner, is advanced python programming.

A first try would be to move your server to an extension. Keep the same context and socket alive when the extension initialize. Then call socket.recv() every frame using an Execute DAT. Socket should be the socket that you initialized in your extension.

This method is blocking, as far as I remember, so you will drop frames. Use flags=NOBLOCK to throw an error if no messages arrived. Catch this error in a try/except.

They are many quirks around ZMQ - and those get impacted by the TouchDesigner workflows and environments as well. Spend time reading the documentation, in depth: The PyZMQ API — PyZMQ 26.0.0.dev0 documentation

If you know how to thread in TouchDesigner, I think you are better off threading everything. There is also AsyncIO methods which could help and fit nicely in a TouchDesigner workflow, but those require quite the python setup as well.



@JetXS clearly knows more about this than I do :wink:

1 Like