Пример #1
0
        private void subThread_DoWork(object sender, DoWorkEventArgs e)
        {
            using (var ctx = ZContext.Create())
            {
                using (var socket = new ZSocket(ctx, ZSocketType.SUB))
                {
                    socket.Connect("tcp://127.0.0.1:5000");
                    //socket.Subscribe("Shopping");
                    socket.SubscribeAll();

                    while (true)
                    {
                        var zmqMessage = socket.ReceiveMessage();

                        var msgTitle = zmqMessage[0].ReadString(Encoding.UTF8);

                        ShoppingBasket shoppingBasket = JsonFrame.DeSerialize <ShoppingBasket>(zmqMessage[1]);

                        Console.WriteLine("SUB; Received: ");
                        Console.WriteLine("\t" + msgTitle);

                        var msg2 = JsonSerializer.SerializeToString <ShoppingBasket>(shoppingBasket);
                        Console.WriteLine("\t" + msg2);
                    }
                }
            }
        }
Пример #2
0
 void subThread_DoWork(object sender, DoWorkEventArgs e)
 {
     using (var ctx = ZmqContext.Create())
     {
         using (var socket = ctx.CreateSocket(SocketType.SUB))
         {
             socket.Connect("tcp://127.0.0.1:5000");
             socket.SubscribeAll();
             while (true)
             {
                 var            zmqMessage     = socket.ReceiveMessage();
                 var            msgTitle       = Encoding.UTF8.GetString(zmqMessage[0]);
                 ShoppingBasket shoppingBasket = JsonFrame
                                                 .DeSerialize <ShoppingBasket>
                                                     (zmqMessage[1]);
                 Console.WriteLine("SUB; Received: ");
                 Console.WriteLine("\t" + msgTitle);
                 Console.WriteLine("\t" + Encoding.UTF8.GetString(zmqMessage[1]));
             }
         }
     }
 }