public ZeroMqDeviceService()
 {
     //We are using NetMQ to retrieve the available devices in the following manner:
     // queryRouterSocket -> querySocket -> All Devices In -> All Device out -> commandSocket -> queryRouterSocket
     // Router            -> Publisher   -> Subscriber     -> Dealer         -> Router        -> Router
     //This pattern allows any client to request the list of Clients in the commandSocket. So we can send messages directly to clients at another point in time.
     queryRouterSocket.ReceiveReady += (o, e) =>
     {
         //Send a message to all clients with the following fields:
         // 1 - Subscription Name
         // 2 - queryRouterSocket id
         // 3 - command type
         var incomingMsg     = e.Socket.ReceiveMultipartBytes();
         var messageToServer = new NetMQMessage();
         messageToServer.Append("All");
         incomingMsg.ForEach((val) => { messageToServer.Append(val); });
         querySocket.SendMultipartMessage(messageToServer);
     };
     commandSocket.ReceiveReady += (o, e) =>
     {
         //Recieve a message from the clients with the following fields:
         // 1 - Client Id
         // 2 - queryRouterSocket id
         // 3 - response
         var msg = commandSocket.ReceiveMultipartBytes();
         msg.RemoveAt(0); //Remove the Client id
         var messageToClient = new NetMQMessage();
         msg.ForEach((val) => { messageToClient.Append(val); });
         queryRouterSocket.SendMultipartMessage(messageToClient); //forward the message
     };
     poller = new NetMQPoller {
         queryRouterSocket, commandSocket
     };
     poller.RunAsync();
 }
Пример #2
0
 internal void doHeartbeat()
 {
     try
     {
         while (true)
         {
             var hb = hbSocket.ReceiveMultipartBytes();
             hbSocket.SendMultipartBytes(hb);
         }
     }
     catch (Exception ex)
     {
         handleException(ex);
     }
 }