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


C# ZSocket.SendFrame方法代码示例

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


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

示例1: Tripping_ClientTask

        static void Tripping_ClientTask(ZContext ctx, ZSocket pipe, CancellationTokenSource cancellor, object[] args)
        {
            using (ZSocket client = new ZSocket(ctx, ZSocketType.DEALER))
            {
                client.Connect("tcp://localhost:5555");
                "Setting up test...".DumpString();
                Thread.Sleep(100);

                int requests;
                "Synchronous round-trip test...".DumpString();
                var start = DateTime.Now;
                Stopwatch sw = Stopwatch.StartNew();
                for (requests = 0; requests < 10000; requests++)
                {
                    using (var outgoing = new ZFrame("hello"))
                    {
                        client.Send(outgoing);
                        using (var reply = client.ReceiveFrame())
                        {
                            if (Verbose)
                                reply.ToString().DumpString();
                        }
                    }
                }
                sw.Stop();
                " {0} calls - {1} ms => {2} calls / second".DumpString(requests, sw.ElapsedMilliseconds, requests * 1000 / sw.ElapsedMilliseconds);

                "Asynchronous round-trip test...".DumpString();
                sw.Restart();
                // sending 100000 requests => often ends in eagain exception in ZContext.Proxy!!
                for (requests = 0; requests < 1000; requests++)
                    using (var outgoing = new ZFrame("hello"))
                        client.SendFrame(outgoing);

                for (requests = 0; requests < 1000; requests++)
                    using (var reply = client.ReceiveFrame())
                        if (Verbose)
                            reply.ToString().DumpString();
                sw.Stop();
                " {0} calls - {1} ms => {2} calls / second".DumpString(requests, sw.ElapsedMilliseconds, requests * 1000 / sw.ElapsedMilliseconds);
                using (var outgoing = new ZFrame("done"))
                    pipe.SendFrame(outgoing);
            }
        }
开发者ID:ray-zong,项目名称:zguide,代码行数:44,代码来源:tripping.cs

示例2: Espresso0_Publisher

        static void Espresso0_Publisher(ZContext context)
        {
            // The publisher sends random messages starting with A-J:
            using (var publisher = new ZSocket(context, ZSocketType.PUB))
            {
                publisher.Bind("tcp://*:6000");

                var rnd = new Random();
                ZError error;
                while (true)
                {
                    var s = String.Format("{0}-{1,0:D5}", (char)(rnd.Next(10) + 'A'), rnd.Next(100000));
                    if (!publisher.SendFrame(new ZFrame(s), out error))
                    {
                        if (error == ZError.ETERM)
                            return; // Interrupted
                        throw new ZException(error);
                    }

                    Thread.Sleep(100); // Wait for 1/10th second
                }
            }
        }
开发者ID:chubbson,项目名称:zguide,代码行数:23,代码来源:espresso0.cs

示例3: Espresso_Publisher

        static void Espresso_Publisher(ZContext context)
        {
            // The publisher sends random messages starting with A-J:

            using (var publisher = new ZSocket(context, ZSocketType.PUB))
            {
                publisher.Bind("tcp://*:6000");

                ZError error;

                while (true)
                {
                    var frame = ZFrame.Create(8);
                    var bytes = new byte[8];
                    using (var rng = new System.Security.Cryptography.RNGCryptoServiceProvider())
                    {
                        rng.GetBytes(bytes);
                    }
                    frame.Write(bytes, 0, 8);

                    if (!publisher.SendFrame(frame, out error))
                    {
                        if (error == ZError.ETERM)
                            return;	// Interrupted
                        throw new ZException(error);
                    }

                    Thread.Sleep(1);
                }
            }
        }
开发者ID:ChenXuJasper,项目名称:zguide,代码行数:31,代码来源:espresso.cs


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