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


C# NetMQSocket.Send方法代码示例

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


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

示例1: DoServer

 protected override void DoServer(NetMQSocket socket, int messageSize)
 {
     for (int i = 0; i < Iterations; i++)
     {
         byte[] message = socket.Receive();
         socket.Send(message);
     }
 }
开发者ID:bbqchickenrobot,项目名称:netmq,代码行数:8,代码来源:LatencyBenchmark.cs

示例2: DoClient

        protected override long DoClient(NetMQSocket socket, int messageSize)
        {
            var msg = new byte[messageSize];

            var watch = Stopwatch.StartNew();

            for (int i = 0; i < Iterations; i++)
            {
                socket.Send(msg);
                socket.Receive(); // ignore response
            }

            return watch.ElapsedTicks;
        }
开发者ID:bbqchickenrobot,项目名称:netmq,代码行数:14,代码来源:LatencyBenchmark.cs

示例3: ZeroMqHub

        /// <summary>
        /// Create a new instance of a Proxy (NetMQ.Proxy)
        /// with the given sockets to serve as a front-end, a back-end, and a control socket.
        /// </summary>
        /// <param name="publisherAddress">the address that messages will be forwarded from</param>
        /// <param name="subscriberAddress">the address that messages should be sent to</param>
        /// <param name="heartbeat">the timespan at which to send HEARTBEAT messages (in milliseconds) - you can set this to zero if not needed</param>
        /// <param name="control">this socket will have messages also sent to it - you can set this to null if not needed</param>
        public ZeroMqHub(string publisherAddress, string subscriberAddress, int heartbeat = 0, NetMQSocket control = null)
        {
            _subscriberAddress = subscriberAddress;
            _publisherAddress = publisherAddress;
            var context = NetMQContext.Create();
            _subscriber = context.CreateXSubscriberSocket();
            _publisher = context.CreateXPublisherSocket();
            _control = control;

            if (heartbeat > 0)
            {
                _heartbeat = new NetMQTimer(heartbeat);
                _heartbeat.Elapsed += (s, a) => _publisher.Send("HEARTBEAT");
            }

            Name = "XPub-XSub";
            PSJobTypeName = typeof(ZeroMqHub).Name;

            _subscriber.Bind(subscriberAddress);
            _publisher.Bind(publisherAddress);
        }
开发者ID:Jaykul,项目名称:PowerBotMQ,代码行数:29,代码来源:ZeroMqHub.cs

示例4: Main

        static void Main(string[] args)
        {
            using (var context = NetMQContext.Create())
            {
                worker = context.CreateRequestSocket();

                var randomizer = new Random(DateTime.Now.Millisecond);
                Guid guid = Guid.NewGuid();
                worker.Options.Identity = Encoding.Unicode.GetBytes(guid.ToString());
                worker.ReceiveReady += WorkerOnReceiveReady;
                worker.Connect(SERVER_ENDPOINT);

                Console.WriteLine("W: {0} worker ready", guid);
                worker.Send(Encoding.Unicode.GetBytes(LRU_READY));

                var cycles = 0;
                while (true)
                {
                    cycles += 1;
                    if (cycles > 3 && randomizer.Next(0, 5) == 0)
                    {
                        Console.WriteLine("W: {0} simulating a crash", guid);
                        System.Threading.Thread.Sleep(5000);
                        //break;
                    }
                    else if (cycles > 3 && randomizer.Next(0, 5) == 0)
                    {
                        Console.WriteLine("W: {0} simulating CPU overload", guid);
                        System.Threading.Thread.Sleep(3000);
                    }
                    Console.WriteLine("W: {0} normal reply", guid);

                    worker.Poll(TimeSpan.FromMilliseconds(1000));
                }

            }
        }
开发者ID:EugenDueck,项目名称:netmq,代码行数:37,代码来源:Program.cs

示例5: Send

 private static void Send(string message, NetMQSocket socket, bool sendMore = true)
 {
     socket.Send(message, false, sendMore);
 }
开发者ID:ashwinsathyar,项目名称:icsharp,代码行数:4,代码来源:MessageSender.cs

示例6: ProxyBetween

        private static void ProxyBetween(NetMQSocket from, NetMQSocket to, [CanBeNull] NetMQSocket control)
        {
            var msg = new Msg();
            msg.InitEmpty();

            var copy = new Msg();
            copy.InitEmpty();

            while (true)
            {
                from.Receive(ref msg, SendReceiveOptions.None);
                bool more = from.Options.ReceiveMore;

                if (control != null)
                {
                    copy.Copy(ref msg);

                    control.Send(ref copy, more ? SendReceiveOptions.SendMore : SendReceiveOptions.None);
                }

                to.Send(ref msg, more ? SendReceiveOptions.SendMore : SendReceiveOptions.None);

                if (!more)
                {
                    break;
                }
            }

            copy.Close();
            msg.Close();
        }
开发者ID:bbqchickenrobot,项目名称:netmq,代码行数:31,代码来源:Proxy.cs

示例7: ProxyBetween

        private static void ProxyBetween(NetMQSocket from, NetMQSocket to, [CanBeNull] NetMQSocket control)
        {
            var msg = new Msg();
            msg.InitEmpty();

            var copy = new Msg();
            copy.InitEmpty();

            while (true)
            {
                from.Receive(ref msg);
                var more = msg.HasMore;

                if (control != null)
                {
                    copy.Copy(ref msg);

                    control.Send(ref copy, more);
                }

                to.Send(ref msg, more);

                if (!more)
                    break;
            }

            copy.Close();
            msg.Close();
        }
开发者ID:romanros,项目名称:netmq,代码行数:29,代码来源:Proxy.cs

示例8: Start

		public async Task Start ()
		{
			ThrowIfDisposed ();
			var ct = cancellationTokenSource.Token;

			nmqPoller = new Poller ();
			nmqScheduler = new NetMQScheduler (nmqContext, nmqPoller);
			nmqServer = nmqContext.CreateResponseSocket ();
			nmqServer.Bind (Address.AbsoluteUri.TrimEnd ('/'));

			serverTask = Task.Factory.StartNew (() => {
				ct.ThrowIfCancellationRequested ();

				while (true) {
					if (ct.IsCancellationRequested) {
						// clean up here
						ct.ThrowIfCancellationRequested ();
					}
					var msg = nmqServer.Receive ();
					var request = Request.Deserialize (msg);
					var result = Handle (request);

					byte[] output_buffer = result.Serialize ();
					nmqServer.Send (output_buffer);
				}
			}, ct);

			await serverTask;
		}
开发者ID:nerdshark,项目名称:CSharpReplAddin,代码行数:29,代码来源:CSharpReplServer.cs

示例9: GetBehaviorModules

 private static IList<BehaviorInfo> GetBehaviorModules(NetMQSocket socket,
     IList<BehaviorInfo> behaviorList)
 {
     var ret = new List<BehaviorInfo>();
     var dict = new Dictionary<string, BehaviorInfo>();
     //behavior_modules
     if (socket != null && behaviorList != null && behaviorList.Count > 0)
     {
         ret.AddRange(behaviorList);
         socket.Send("behavior_modules");
         var resp = socket.ReceiveString(new TimeSpan(0, 0, 0, 0, RecvTimeout));
         if (!string.IsNullOrEmpty(resp))
         {
             var modules = JArray.Parse(resp);
             if (modules != null && modules.Count > 0)
             {
                 //Console.WriteLine(resp);
                 foreach (var module in modules)
                 {
                     var moduleName = module.Value<string>("name");
                     var responder = module.SelectToken("$.responder");
                     string host = string.Empty;
                     int port = 0;
                     if (responder != null)
                     {
                         host = responder.Value<string>("Host");
                         port = responder.Value<int>("Port");
                     }
                     var behaviors = module.SelectToken("$.behaviors");
                     foreach (var behavior in behaviors)
                     {
                         string name = behavior.Value<string>("name");
                         string functionName = behavior.Value<string>("function_name");
                         var args = behavior.SelectToken("$.arg");
                         var parameters = new Dictionary<string, object>();
                         foreach (var arg in args)
                         {
                             parameters.Add(arg.Value<string>("name"), new Dictionary<string, object>
                             {
                                 {"value", arg.Value<string>("value")},
                                 {"place_holder", arg.Value<string>("place_holder")},
                                 {"type", arg.Value<string>("type")}
                             });
                         }
                         var matchingBehaviors = ret.Where(s => s.BehaviorName == name).ToList();
                         foreach (var matchingBehavior in matchingBehaviors)
                         {
                             matchingBehavior.ModuleName = moduleName;
                             matchingBehavior.FunctionName = functionName;
                             matchingBehavior.Ip = host;
                             matchingBehavior.Port = port;
                             foreach (var parameter in parameters)
                             {
                                 if (!matchingBehavior.Parameters.ContainsKey(parameter.Key))
                                 {
                                     matchingBehavior.Parameters.Add(parameter);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return ret;
 }
开发者ID:praveenv4k,项目名称:indriya,代码行数:66,代码来源:MainProgram.cs

示例10: GetBehaviorModules2

        private static IList<BehaviorInfo> GetBehaviorModules2(NetMQSocket socket,
            IList<BehaviorInfo> behaviorList)
        {
            var ret = new List<BehaviorInfo>();
            var dict = new Dictionary<string, BehaviorInfo>();
            //behavior_modules
            if (socket != null && behaviorList != null && behaviorList.Count > 0)
            {
                socket.Send("behavior_modules");
                var resp = socket.ReceiveString(new TimeSpan(0, 0, 0, 0, RecvTimeout));
                if (!string.IsNullOrEmpty(resp))
                {
                    var modules = JArray.Parse(resp);
                    if (modules != null && modules.Count > 0)
                    {
                        //Console.WriteLine(resp);
                        foreach (var module in modules)
                        {
                            var moduleName = module.Value<string>("name");
                            var responder = module.SelectToken("$.responder");
                            string host = string.Empty;
                            int port = 0;
                            if (responder != null)
                            {
                                host = responder.Value<string>("Host");
                                port = responder.Value<int>("Port");
                            }
                            var behaviors = module.SelectToken("$.behaviors");
                            foreach (var behavior in behaviors)
                            {
                                string name = behavior.Value<string>("name");
                                string functionName = behavior.Value<string>("function_name");
                                var parameters = new Dictionary<string, object>();
                                var args = behavior.SelectToken("$.arg");
                                foreach (var arg in args)
                                {
                                    parameters.Add(arg.Value<string>("name"), new Dictionary<string, object>
                                    {
                                        {"value", arg.Value<string>("value")},
                                        {"place_holder", arg.Value<string>("place_holder")},
                                        {"type", arg.Value<string>("type")}
                                    });
                                }
                                if (!dict.ContainsKey(name))
                                {
                                    dict.Add(name, new BehaviorInfo
                                    {
                                        BehaviorName = name,
                                        FunctionName = functionName,
                                        Ip = host,
                                        Port = port,
                                        Parameters = parameters
                                    });
                                }
                            }
                        }
                    }
                }
                if (dict.Count > 0)
                {

                    // ReSharper disable once LoopCanBeConvertedToQuery
                    foreach (var item in behaviorList)
                    {
                        Log.InfoFormat("Before : {0}",item.ToString());
                        if (dict.ContainsKey(item.BehaviorName))
                        {
                            var temp = dict[item.BehaviorName].Clone() as BehaviorInfo;
                            if (temp != null)
                            {
                                foreach (var parameter in item.Parameters)
                                {
                                    if (!temp.Parameters.ContainsKey(parameter.Key))
                                    {
                                        temp.Parameters.Add(parameter);
                                    }
                                    else
                                    {
                                        temp.Parameters[parameter.Key] = parameter.Value;
                                    }
                                }
                                Log.InfoFormat("After : {0}", temp.ToString());
                                ret.Add(temp);
                            }

                            //ret.Add(dict[item.BehaviorName]);
                            // Update the values of the parameter list with the once originally parsed from the xml file
                            //foreach (var parameter in item.Parameters)
                            //{
                            //    if (!dict[item.BehaviorName].Parameters.ContainsKey(parameter.Key))
                            //    {
                            //        dict[item.BehaviorName].Parameters.Add(parameter);
                            //    }
                            //    else
                            //    {
                            //        dict[item.BehaviorName].Parameters[parameter.Key] = parameter.Value;
                            //    }
                            //}
                            //ret.Add(dict[item.BehaviorName]);
                        }
//.........这里部分代码省略.........
开发者ID:praveenv4k,项目名称:indriya,代码行数:101,代码来源:MainProgram.cs

示例11: DoServer

        protected override void DoServer(NetMQSocket socket, int messageSize)
        {
            var msg  = new Msg();
            msg.InitEmpty();

            for (int i = 0; i < Iterations; i++)
            {
                socket.Receive(ref msg);

                socket.Send(ref msg, more: false);
            }
        }
开发者ID:cjkao,项目名称:netmq,代码行数:12,代码来源:LatencyBenchmark.cs

示例12: AcceptDataAdditionRequest

        /// <summary>
        /// Handles incoming data "push" requests: the client sends data for us to add to local storage.
        /// </summary>
        private void AcceptDataAdditionRequest(string requesterIdentity, NetMQSocket socket)
        {
            //final message part: receive the DataAdditionRequest object
            bool hasMore;
            var ms = new MemoryStream();
            byte[] buffer = socket.Receive(out hasMore);

            var request = MyUtils.ProtoBufDeserialize<DataAdditionRequest>(buffer, ms);

            //log the request
            Log(LogLevel.Info, string.Format("Received data push request for {0}.",
                request.Instrument.Symbol));

            //start building the reply
            socket.SendMore(requesterIdentity);
            socket.SendMore("PUSHREP");
            try
            {
                _broker.AddData(request);
                socket.Send("OK");
            }
            catch (Exception ex)
            {
                socket.SendMore("ERROR");
                socket.Send(ex.Message);
            }
        }
开发者ID:ychaim,项目名称:qdms,代码行数:30,代码来源:HistoricalDataServer.cs

示例13: AcceptAvailableDataRequest

        /// <summary>
        /// Handles requests for information on data that is available in local storage
        /// </summary>
        private void AcceptAvailableDataRequest(string requesterIdentity, NetMQSocket socket)
        {
            //get the instrument
            bool hasMore;
            var ms = new MemoryStream();
            byte[] buffer = socket.Receive(out hasMore);

            var instrument = MyUtils.ProtoBufDeserialize<Instrument>(buffer, ms);

            //log the request
            Log(LogLevel.Info, string.Format("Received local data storage info request for {0}.",
                instrument.Symbol));

            //and send the reply

            var storageInfo = _broker.GetAvailableDataInfo(instrument);
            socket.SendMore(requesterIdentity);
            socket.SendMore("AVAILABLEDATAREP");

            socket.SendMore(MyUtils.ProtoBufSerialize(instrument, ms));

            socket.SendMore(BitConverter.GetBytes(storageInfo.Count));
            foreach (StoredDataInfo sdi in storageInfo)
            {
                socket.SendMore(MyUtils.ProtoBufSerialize(sdi, ms));
            }
            socket.Send("END");
        }
开发者ID:ychaim,项目名称:qdms,代码行数:31,代码来源:HistoricalDataServer.cs


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