OK, so I want to make a (zmq) TCP server (gh) component and have it spinning waiting for requests. Now, a code snippet like the below would block the main thread in GH and thus render it useless. So I would have to run it in a separate thread I guess. But what would this mean for the rest of Grashopper? Would the rest of the GH definition (like downstream components) be able to handle any output from such a component spining in a separate thread?
In short, how should I set up a service like this?
public static void CnServer(string[] args)
{
...
string name = args[0];
// Create responder
using (var context = new ZContext())
using (var responder = new ZSocket(context, ZSocketType.REP))
{
responder.Bind("tcp://*:5555");
while (true)
{
using (ZFrame request = responder.ReceiveFrame())
{
RhinoApp.WriteLine("Received {0}", request.ReadString());
Thread.Sleep(1); // Do some work
responder.Send(new ZFrame(name));
}
}
}
}
// Rolf