Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void Setup(CancellationToken cancellationToken)
- {
- using (ZmqSocket frontend = this.Context.CreateSocket(SocketType.SUB), backend = this.Context.CreateSocket(SocketType.PUB))
- {
- frontend.Bind("tcp://*:5550");
- frontend.SubscribeAll();
- // This is our public endpoint for subscribers
- backend.Bind("tcp://*:5553"); // i use local to be able to run the example, this could be the public ip instead eg. tcp://10.1.1.0:8100
- //var device = new ZeroMQ.Devices.ForwarderDevice(this.Context, "tcp://*:5556", "tcp://*:5555", DeviceMode.Blocking);
- //device.Start();
- // Shunt messages out to our own subscribers
- int i = 0;
- try
- {
- while (true)
- {
- bool hasMore = true;
- var zmqMessage = new ZmqMessage();
- while (hasMore)
- {
- Writeline("waiting on receive frame");
- Frame frame = frontend.ReceiveFrame();
- zmqMessage.Append(new Frame(frame.Buffer));
- hasMore = frontend.ReceiveMore;
- }
- i++;
- Writeline(i.ToString());
- backend.SendMessage(zmqMessage);
- cancellationToken.ThrowIfCancellationRequested();
- }
- }
- catch (Exception ex)
- {
- Writeline("cancelled gracefully exit " + ex.Message);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment