Esempio n. 1
0
        public string Export(string token, InDelegate callback)
        {
            using (var context = ZmqContext.Create())
                using (var socket = context.CreateSocket(SocketType.SUB))
                {
                    socket.Connect("tcp://localhost:22220");
                    if (token == "")
                    {
                        socket.SubscribeAll();
                    }
                    else
                    {
                        byte[] UTF8bytes = Encoding.UTF8.GetBytes(token);
                        socket.Subscribe(UTF8bytes);
                    }

                    while (true)
                    {
                        Frame  request  = null;
                        String envelope = null;
                        String message  = null;
                        if (token == "")
                        {
                            request = socket.ReceiveFrame();
                            message = Encoding.UTF8.GetString(request);
                            callback(null, message);
                        }
                        else
                        {
                            request  = socket.ReceiveFrame();
                            envelope = Encoding.UTF8.GetString(request);
                            request  = socket.ReceiveFrame();
                            message  = Encoding.UTF8.GetString(request);
                            callback(envelope, message);
                        }
                        Thread.Sleep(10);
                    }
                }
        }
        public string Export(string token, InDelegate callback)
        {
            using (var context = ZmqContext.Create())
            using (var socket = context.CreateSocket(SocketType.SUB))
            {
                socket.Connect("tcp://localhost:22220");
                if (token == "")
                {
                    socket.SubscribeAll();
                }
                else
                {
                    byte[] UTF8bytes = Encoding.UTF8.GetBytes(token);
                    socket.Subscribe(UTF8bytes);
                }

                while (true)
                {
                    Frame request = null;
                    String envelope = null;
                    String message = null;
                    if (token == "")
                    {
                        request = socket.ReceiveFrame();
                        message = Encoding.UTF8.GetString(request);
                        callback(null, message);
                    }
                    else
                    {
                        request = socket.ReceiveFrame();
                        envelope = Encoding.UTF8.GetString(request);
                        request = socket.ReceiveFrame();
                        message = Encoding.UTF8.GetString(request);
                        callback(envelope, message);
                    }
                    Thread.Sleep(10);
                }
            }
        }