public ServiceReporter(IMetricsRegistry registry, ZmqContext context, string endpoint) : base(registry) { context_ = context; socket_ = context_.Socket(SocketType.DEALER); endpoint_ = "tcp://" + endpoint; }
public WebNect() { this.context = new OpenNI.Context(SAMPLE_XML_FILE); this.sessionManager = new NITE.SessionManager(this.context, "Click", "RaiseHand"); this.context.StartGeneratingAll(); this.sessionManager.SessionStart += new EventHandler<NITE.PositionEventArgs>(sessionManager_SessionStart); this.sessionManager.SessionFocusProgress += new EventHandler<NITE.SessionProgressEventArgs>(sessionManager_SessionProgress); this.sessionManager.SessionEnd += sessionManager_SessionEnd; this.waveDetector = new NITE.WaveDetector(); this.waveDetector.Wave += waveDetector_Wave; this.waveDetector.PointUpdate += new EventHandler<HandEventArgs>(waveDetector_PointUpdate); this.sessionManager.AddListener(this.waveDetector); this.zmq_context = new ZMQ.Context(1); this.zmq_publisher = this.zmq_context.Socket(SocketType.PUB); this.zmq_publisher.Bind(this.SOCKET_SOURCE); Console.WriteLine("ZMQ Socket at {0}", this.SOCKET_SOURCE); this.shouldRun = true; this.readerThread = new Thread(ReaderThread); this.readerThread.Start(); }
public Connection(string url) { this.url = url; this.context = new ZMQ.Context(1); this.reqSocket = this.context.Socket (SocketType.REQ); //this.subSocket = this.context.Socket (SocketType.SUB); this.reqSocket.Connect (this.url); //this.subSocket.Connect (this.url); }
public static void CopyDrawings(XmlDocument xmlResult, string url) { //Copy XML and order to GR_Cfg_DocumentQueue and send process-command through message queue to remote Windows service try { DatabaseFactory.InsertDocumentRecord(xmlResult, Triggers.pubOrderNumber, Triggers.dbEnvironment, StagingUtilities.dbSite, C1WebService.SPOrderNumber); } catch (System.Exception dbf1) { Triggers.logEvent = "ERROR QR: " + dbf1.Message; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, Triggers.logEvent, System.Diagnostics.EventLogEntryType.Information, 234); } Triggers.logEvent = "Signal Message Queue to begin document processing for: " + Triggers.pubOrderNumber + " -> " + C1WebService.SPOrderNumber; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, Triggers.logEvent, System.Diagnostics.EventLogEntryType.Information, 234); //Send command to ZMQ listener to process newly created record from queue //setup using (ZMQ.Context context = new ZMQ.Context()) { using (ZMQ.Socket requester = context.Socket(ZMQ.SocketType.REQ)) { //connect to remote endpoint, <server> if (Triggers.dbEnvironment == "PROD") { requester.Connect("tcp://192.168.23.19:5555"); //grc000dmzbus } else { requester.Connect("tcp://172.16.1.60:5555"); //grctslsql0 (dev) } //send on the REQ pattern string requestText = "PROCESS:" + Triggers.pubOrderNumber; requester.Send(Encoding.ASCII.GetBytes(requestText.ToCharArray())); //receive Response on the REP pattern string ackMsg = requester.Recv(Encoding.ASCII); Triggers.logEvent = "Message received from ZMQ: " + ackMsg; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, Triggers.logEvent, System.Diagnostics.EventLogEntryType.Information, 234); } } //If site was not NOVB, disable the C1Order trigger for the order-site and then move the queue record to the appropriate site queue table switch (StagingUtilities.dbSite) { case "NOVB": //do nothing break; default: DatabaseFactory.MoveQueueRecord(Triggers.pubOrderNumber, StagingUtilities.dbSite); break; } }
public Client(string address, int port = 4949) { ctx = new Context(4); sock = ctx.Socket(SocketType.REQ); // TODO: set me bmp = new Bitmap(640, 480, PixelFormat.Format16bppRgb555); sock.Connect("tcp://"+address+":"+port.ToString()); buf = new byte[640*480*3]; // w*h*BYTES PER PIXEL! dcmp = new LZ4Decompressor64(); // returns appropriate sized decompressor decompressed = new byte[640 * 480 * 3]; }
public static void ProcessingLoop() { if (!SlipstreamEnvironment.Initialized) { throw new InvalidOperationException( "Unable to start PRC-Handler thread, please initialize the environment first."); } var broadcastUrl = SlipstreamEnvironment.Settings.BroadcastUrl; var rpcHandlerUrl = SlipstreamEnvironment.Settings.RpcHandlerUrl; var id = Guid.NewGuid(); LoggerProvider.EnvironmentLogger.Debug( () => string.Format("Starting RpcHandler thread[{0}] URL=[{1}] ...", id, rpcHandlerUrl)); using (var broadcastSocket = new ZMQ.Socket(ZMQ.SocketType.SUB)) using (var receiver = new ZMQ.Socket(ZMQ.SocketType.REP)) { broadcastSocket.Connect(broadcastUrl); broadcastSocket.Subscribe("STOP-RPC", Encoding.UTF8); LoggerProvider.EnvironmentLogger.Debug( () => string.Format("RpcHandler thread[{0}] is connected to the Commander URL[{1}]", id, broadcastUrl)); receiver.Connect(rpcHandlerUrl); var items = new PollItem[2]; items[0] = broadcastSocket.CreatePollItem(IOMultiPlex.POLLIN); items[0].PollInHandler += new PollHandler(BusControllerPollInHandler); items[1] = receiver.CreatePollItem(IOMultiPlex.POLLIN); items[1].PollInHandler += new PollHandler(ReceiverPollInHandler); lock (s_lockObj) { s_running = true; } // Process messages from both sockets while (s_running) { Context.Poller(items, -1); } LoggerProvider.EnvironmentLogger.Debug( () => string.Format("The RpcHandler thread[{0}] is stopped", id)); } }
/// <summary> /// Sets socket Identity to a random number. /// </summary> /// <param name="socket">ZMQ Socket</param> public static string SetID(Socket socket, Encoding encoding) { Random rand = GetRandomGen(); string id = rand.Next().ToString() + "-" + rand.Next().ToString(); socket.StringToIdentity(id, encoding); return id; }
/// <summary> /// Prints all pending messages to the console. /// </summary> /// <param name="socket">ZMQ Socket</param> public static void Dump(Socket socket, Encoding encoding) { Console.WriteLine(new String('-', 38)); foreach (byte[] msg in socket.RecvAll()) { Console.Write("[{0}] ", String.Format("{0:d3}", msg.Length)); if (msg.Length == 17 && msg[0] == 0) { Console.WriteLine(ZHelpers.DecodeUUID(msg).Substring(1)); } else { Console.WriteLine(encoding.GetString(msg)); } } }
/// <summary> /// Sets socket Identity to a random number. /// </summary> /// <param name="socket">ZMQ Socket</param> /// <param name="encoding">Encoding to use for the socket identity</param> /// <returns>The identity assigned to the socket.</returns> public static string SetID(Socket socket, Encoding encoding) { if (socket == null) { throw new ArgumentNullException("socket"); } Random rand = GetRandomGen(); string id = rand.Next() + "-" + rand.Next(); socket.StringToIdentity(id, encoding); return id; }
/// <summary> /// Prints all pending messages to the console. /// </summary> /// <param name="socket">ZMQ Socket</param> /// <param name="encoding">Encoding to use for message decoding</param> public static void Dump(Socket socket, Encoding encoding) { if (socket == null) { throw new ArgumentNullException("socket"); } Console.WriteLine(new String('-', 38)); foreach (byte[] msg in socket.RecvAll()) { Console.Write("[{0}] ", String.Format("{0:d3}", msg.Length)); if (msg.Length == 17 && msg[0] == 0) { Console.WriteLine(DecodeUUID(msg).Substring(1)); } else { Console.WriteLine(encoding.GetString(msg)); } } }
public Socket(MachineContext context, ZMQ.Socket zmqSocket) { _context = context; _zmqSocket = zmqSocket; }
/// <summary> /// Should not be created directly, use Socket.CreatePollItem /// </summary> /// <param name="zmqPollItem">Native poll item</param> /// <param name="socket">Socket to poll</param> internal PollItem(ZMQPollItem zmqPollItem, Socket socket) { _socket = socket; _zmqPollItem = zmqPollItem; }
/// <summary> /// Should not be created directly, use Socket.CreatePollItem /// </summary> /// <param name="zmqPollItem">Native poll item</param> /// <param name="socket">Socket to poll</param> internal PollItem(ZMQPollItem zmqPollItem, Socket socket) { if (socket == null) { throw new ArgumentNullException("socket"); } _socket = socket; _zmqPollItem = zmqPollItem; }