当前位置: 首页>>代码示例>>C#>>正文


C# ZmqSocket.ReceiveMessage方法代码示例

本文整理汇总了C#中ZmqSocket.ReceiveMessage方法的典型用法代码示例。如果您正苦于以下问题:C# ZmqSocket.ReceiveMessage方法的具体用法?C# ZmqSocket.ReceiveMessage怎么用?C# ZmqSocket.ReceiveMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ZmqSocket的用法示例。


在下文中一共展示了ZmqSocket.ReceiveMessage方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SendRequest

        public static void SendRequest(Int32 request,ref ZmqSocket socket)
        {
            //ZmqSocket socket;
            try
            {
                //socket = CreateSocket();

                var message = new ZmqMessage();
                message.Append(Encoding.UTF8.GetBytes(String.Format(" Hello {0}.", request)));

                socket.SendMessage(message);

                // TODO: add receive timeout as param
                var dataResult = socket.ReceiveMessage();

                Console.WriteLine(Encoding.UTF8.GetString(dataResult[0]));
                Console.WriteLine(Encoding.UTF8.GetString(dataResult[1]));

            }
            catch (Exception ex)
            {
                socket.Close();
                socket = CreateSocket();
                Console.WriteLine(ex.ToString());
            }
        }
开发者ID:maslakov,项目名称:zmqtests,代码行数:26,代码来源:Program.cs

示例2: Receive

        public void Receive(ZmqSocket ZmqSocket)
        {
            var zmqMessage = ZmqSocket.ReceiveMessage();

            foreach (var frame in zmqMessage)
            {
                frames.Insert(0, frame.Buffer);
            }
        }
开发者ID:Jay-Krish,项目名称:zguide,代码行数:9,代码来源:zmsg.cs

示例3: OnSendComplete

        protected override OpStatus OnSendComplete(ZmqSocket Socket)
        {
            // Request-replay socket (REQ) should immideatly receive message just after 'send'
#if DEBUG
            System.Console.WriteLine("[RequestReplaySocket] Before receiveng the package");
            System.Console.WriteLine("[RequestReplaySocket] Current thread ID:" + System.Threading.Thread.CurrentThread.ManagedThreadId.ToString());
#endif

            ZmqMessage okMessage = Socket.ReceiveMessage(TimeSpan.FromSeconds(1));

#if DEBUG
            System.Console.WriteLine("[RequestReplaySocket] Replay message was received. Status is: " + Socket.ReceiveStatus.ToString());
#endif
            return Socket.ReceiveStatus.Convert();
        }
开发者ID:jasper22,项目名称:UbuntuUsbMonitor,代码行数:15,代码来源:RequestReplaySocket.cs

示例4: Dump

        public static void Dump(ZmqSocket socket, Encoding encoding)
        {
            if (socket == null)
            {
                throw new ArgumentNullException("socket");
            }

            Console.WriteLine(new String('-', 38));
            ZmqMessage message = socket.ReceiveMessage();
            foreach (var frame in message)
            {
                Console.Write("[{0:d3}] ", frame.BufferSize);

                if (frame.BufferSize == 5 && frame.Buffer[0] == 0)
                    Console.WriteLine("{0}", BitConverter.ToString(frame.Buffer).Replace("-", string.Empty));
                else
                    Console.WriteLine("{0}", encoding.GetString(frame.Buffer));
            }
        }
开发者ID:Jay-Krish,项目名称:zguide,代码行数:19,代码来源:ZHelpers.cs

示例5: ClientThread

        private void ClientThread()
        {
            try
            {

                status = 1;
                context = ZmqContext.Create();
                socket = context.CreateSocket(SocketType.DEALER);
                window.SetProgress(5);
                window.SetStatus("Contacting server...");
                window.Log("Attempting connection to server...");
                window.Log("   --> " + Settings.Default.ServerAddress);
                bool connected = false;
                {
                    byte[] identity = new byte[15];
                    new Random().NextBytes(identity);
                    socket.Identity = identity;
                    var helloMessage = new[] { (byte)MessageIdentifier.Init };
                    int attempt = 1;
                    var endpoint = Settings.Default.ServerAddress;
                    socket.Connect(endpoint);
                    socket.Send(helloMessage);
                    while (!connected)
                    {
                        var message = socket.ReceiveMessage(TimeSpan.FromSeconds(5));
                        if (message.TotalSize == 0)
                        {
                            window.Log("(" + attempt + ") Failed to connect, trying again in 5 seconds...");
                        }
                        else
                        {
                            window.Log("Received response, verifying...");

                            //check command value
                            if (message.First.Buffer[0] == (byte)MessageIdentifier.SetIdentity)
                            {
                                assignedIdentity = message.First.Buffer.Skip(1).ToArray();
                                window.Log("Received a new " + assignedIdentity.Length + " byte identity.");
                                socket.Identity = assignedIdentity;
                                socket.Disconnect(endpoint);
                                var finalSocket = context.CreateSocket(SocketType.DEALER);
                                socket.Dispose();
                                socket = finalSocket;
                                socket.Identity = assignedIdentity;
                                socket.TcpKeepalive = TcpKeepaliveBehaviour.Enable;
                                socket.Connect(endpoint);
                                socket.Send(new byte[] { (byte)MessageIdentifier.SetIdentity });
                                break;
                            }
                            if (message.First.Buffer[0] == (byte)MessageIdentifier.InvalidIdentity)
                            {
                                window.Log("Server responded with invalid identity. Trying again.");
                            }
                        }
                        attempt++;
                        Thread.Sleep(5000);
                    }
                    window.Log("Connected to master server after " + attempt + " attempts.");
                    window.SetProgress(20);
                    window.SetStatus("Synchronizing encryption...");

                }
                //We are connected!
                window.Log("Waiting for encryption sequence...");
                ZmqMessage msg = socket.ReceiveMessage();
                if (msg.First.Buffer[0] != (byte)MessageIdentifier.BeginEncryption)
                {
                    LogUnexpectedMessage(msg.First.Buffer);
                    window.Log("Crucial unexpected result, disconnecting.");
                    socket.Send(new byte[] { (byte)MessageIdentifier.Disconnect });
                    status = 0;
                    socket.Dispose();
                    context.Dispose();
                    return;
                }

                window.Log("Sending encryption key...");
                byte[] encryptMsg = new byte[1 + keyHash.Length];
                encryptMsg[0] = (byte)MessageIdentifier.BeginEncryption;
                keyHash.CopyTo(encryptMsg, 1);
                socket.Send(encryptMsg);

                window.Log("Waiting for response...");

                msg = socket.ReceiveMessage();

                if (msg.First.Buffer[0] != (byte)MessageIdentifier.ConfirmEncryption)
                {
                    window.Log("Invalid encryption key. Exiting...");
                    status = 0;
                    socket.Send(BuildMessage(MessageIdentifier.Disconnect, null, false));
                    return;
                }

                string salt = Encoding.UTF8.GetString(DecryptMessage(msg.First.Buffer.Skip(1).ToArray()));

                heartbeat.Start();

                window.Log("Connected, encrypted, beginning login.");
                window.SetStatus("Logging in...");
//.........这里部分代码省略.........
开发者ID:paralin,项目名称:MatrixServer,代码行数:101,代码来源:ClientManager.cs


注:本文中的ZmqSocket.ReceiveMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。