ROUTER-to-REP in Haxe

package ;
import neko.Lib;
import neko.Sys;
import org.zeromq.ZContext;
import org.zeromq.ZMQ;
import org.zeromq.ZMQSocket;
import org.zeromq.ZFrame;

* Custom routing Router to Papa (ROUTER to REP)
* We will do this all in one thread to emphasize the sequence
* of events…
* See:

class RTPapa

public static function main() {
Lib.println("** RTPapa (see:");

var context:ZContext = new ZContext();
var client:ZMQSocket = context.createSocket(ZMQ_ROUTER);
var worker:ZMQSocket = context.createSocket(ZMQ_REP);
worker.setsockopt(ZMQ_IDENTITY, Bytes.ofString("A"));

// Wait for the worker to connect so that when we send a message
// with a routing envelope, it will actually match the worker…

// Send papa address, address stack, empty part, and request
ZFrame.newStringFrame("A").send(client, ZFrame.ZFRAME_MORE);
ZFrame.newStringFrame("address 3").send(client, ZFrame.ZFRAME_MORE);
ZFrame.newStringFrame("address 2").send(client, ZFrame.ZFRAME_MORE);
ZFrame.newStringFrame("address 1").send(client, ZFrame.ZFRAME_MORE);
ZFrame.newStringFrame("").send(client, ZFrame.ZFRAME_MORE);
ZFrame.newStringFrame("This is the workload").send(client);

// Worker should just get the workload

// We don't play with the envelopes in the worker
ZFrame.newStringFrame("This is the reply").send(worker);

// Now we dump what we got off the ROUTER socket