// We will do this all in one thread to emphasize the sequence // of events... static void Main(string[] args) { using (Context ctx = new Context(1)) { using (Socket client = ctx.Socket(SocketType.XREP), worker = ctx.Socket(SocketType.REP)) { client.Bind("inproc://routing"); worker.StringToIdentity("A", Encoding.Unicode); worker.Connect("inproc://routing"); // Wait for the worker to connect so that when we send a message // with routing envelope, it will actually match the worker... Thread.Sleep(1000); // Send papa address, address stack, empty part, and request client.SendMore("A", Encoding.Unicode); client.SendMore("address 3", Encoding.Unicode); client.SendMore("address 2", Encoding.Unicode); client.SendMore("address 1", Encoding.Unicode); client.SendMore("", Encoding.Unicode); client.Send("This is the workload", Encoding.Unicode); // Worker should get just the workload ZHelpers.Dump(worker, Encoding.Unicode); // We don't play with envelopes in the worker worker.Send("This is the reply", Encoding.Unicode); // Now dump what we got off the XREP socket... ZHelpers.Dump(client, Encoding.Unicode); } } }
public static void Main(string[] args) { using (var context = new Context()) { using (Socket sink = context.Socket(SocketType.ROUTER), anonymous = context.Socket(SocketType.REQ), identified = context.Socket(SocketType.REQ)) { sink.Bind("inproc://example"); // First allow 0MQ to set the identity anonymous.Connect("inproc://example"); anonymous.Send("ROUTER uses a generated UUID", Encoding.Unicode); ZHelpers.Dump(sink, Encoding.Unicode); // Then set the identity ourselves identified.StringToIdentity("PEER2", Encoding.Unicode); identified.Connect("inproc://example"); identified.Send("ROUTER socket uses REQ's socket identity", Encoding.Unicode); ZHelpers.Dump(sink, Encoding.Unicode); } } }
static void Main(string[] args) { using (Context ctx = new Context()) { using (Socket sink = ctx.Socket(SocketType.XREP), anonymous = ctx.Socket(SocketType.REQ), identified = ctx.Socket(SocketType.REQ)) { sink.Bind("inproc://example"); // First allow 0MQ to set the identity anonymous.Connect("inproc://example"); anonymous.Send("XREP uses a generated UUID", Encoding.Unicode); ZHelpers.Dump(sink, Encoding.Unicode); // Then set the identity ourself identified.StringToIdentity("Hello", Encoding.Unicode); identified.Connect("inproc://example"); identified.Send("XREP socket uses REQ's socket identity", Encoding.Unicode); ZHelpers.Dump(sink, Encoding.Unicode); } } }