Create custom event handler for distributed messages (ZeroMQ)

Hi,

I’m looking for a way to create a custom event handler that waits for messages that are sent by another tool via ZeroMQ. These messages contain data to control the creation of components like curves and rectangles.

Is there a way to do so? I thought of creating a thread that waits for the messages to arrive and this delegates then the UI thread to draw the objects.

I hope you can help me here,
Pascal

Hi Pascal - I’m moving this thread to the Developer’s forum - I think you’ll have more luck there.

-Pascal

Hi Pascal,

I assume you are asking about this:

http://zeromq.org/

I notice they have a Python sample.

In general, dealing with events and threads is better handled by a plug-in than a Python script (in Rhino).

It appears they support C#, so this may be an option for you.

Just curious, what are you working on?

– Dale

Hi Dale,

Yes, that’s what I’m using. Currently I’m trying to setup the message subscriber like this:

ZContext context = new ZContext();
ZSocket subscriber = new ZSocket(context, ZSocketType.SUB);

subscriber.Connect("tcp://localhost:5561");
subscriber.Subscribe("B");

while (true)
{
    RhinoApp.WriteLine("Running...");

    ZMessage message = subscriber.ReceiveMessage();

    string address = message[0].ReadString();
    string contents = message[1].ReadString();

    RhinoApp.WriteLine("{0}. [{1}] {2}", subscribed, address, contents);
}

return Result.Success;

Currently it gets stuck during creation of the ZContext and I don’t know why… I’ll try to use NetMQ and hope this works here.

My first plugin version just implements a command which has to be called and then waits (or would wait, if it won’t get stuck…) for arriving messages, but it would be nice, to have a thread that does the job and waits for incoming messages.

Cheers,
Pascal

Ah yeah and the purpose of my plugin is to create curves and stuff in other tools like Illustrator and this shows up in Rhino. Currently it’s just a tryout for further implementations.