Advertisement
Guest User

Subscriber

a guest
May 23rd, 2011
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Threading;
  5. using ZMQ;
  6.  
  7. namespace HwmClient
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Context context = new Context(1);
  14.  
  15.             Socket subSocket = context.Socket(SocketType.SUB);
  16.             subSocket.Subscribe(string.Empty, Encoding.UTF8);
  17.             subSocket.HWM = 10;
  18.             subSocket.Connect("tcp://127.0.0.1:5555");
  19.  
  20.             int expectedMsgId = 1;
  21.  
  22.             while (true)
  23.             {
  24.                 string msg = subSocket.Recv(Encoding.UTF8);
  25.  
  26.                 int rxMsgId = int.Parse(msg);
  27.  
  28.                 if (rxMsgId != expectedMsgId)
  29.                 {
  30.                     Console.WriteLine("Expected {0}, but received {1}", expectedMsgId, rxMsgId);
  31.                 }
  32.                 else
  33.                 {
  34.                     Console.WriteLine("Received expected message: {0,12}", rxMsgId);
  35.                 }
  36.  
  37.                 expectedMsgId = rxMsgId + 1;
  38.             }
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement