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


C# zmq.Msg类代码示例

本文整理汇总了C#中NetMQ.zmq.Msg的典型用法代码示例。如果您正苦于以下问题:C# Msg类的具体用法?C# Msg怎么用?C# Msg使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Msg类属于NetMQ.zmq命名空间,在下文中一共展示了Msg类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static int Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("usage: remote_thr <connect-to> <message-size> <message-count>");
                return 1;
            }

            string connectTo = args[0];
            int messageSize = int.Parse(args[1]);
            int messageCount = int.Parse(args[2]);

            var context = ZMQ.CtxNew();
            var pushSocket = ZMQ.Socket(context, ZmqSocketType.Push);
            pushSocket.Connect(connectTo);

            for (int i = 0; i != messageCount; i++)
            {
                var message = new Msg(messageSize);
                pushSocket.Send(message, SendReceiveOptions.None);
            }

            pushSocket.Close();
            context.Terminate();

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

示例2: XSetSocketOption

        protected override bool XSetSocketOption(ZmqSocketOptions option, Object optval)
        {
            if (option != ZmqSocketOptions.Subscribe && option != ZmqSocketOptions.Unsubscribe)
            {
                ZError.ErrorNumber = (ErrorNumber.EINVAL);
                return false;
            }

            byte[] val;

            if (optval is String)
                val =  Encoding.ASCII.GetBytes ((String)optval);
            else if (optval is byte[])
                val = (byte[]) optval;
            else
                throw new ArgumentException();

            //  Create the subscription message.
            Msg msg = new Msg(val.Length + 1);
            if (option == ZmqSocketOptions.Subscribe)
                msg.Put((byte)1);
            else if (option == ZmqSocketOptions.Unsubscribe)
                msg.Put((byte)0);
            msg.Put (val,1);

            //  Pass it further on in the stack.
            bool rc = base.XSend (msg, 0);
            return rc;
        }
开发者ID:oskarwkarlsson,项目名称:netmq,代码行数:29,代码来源:Sub.cs

示例3: RawMessageReady

        bool RawMessageReady()
        {
            //  Destroy content of the old message.
            m_inProgress = null;

            //  Read new message. If there is none, return false.
            //  Note that new state is set only if write is successful. That way
            //  unsuccessful write will cause retry on the next state machine
            //  invocation.
            if (m_msgSource == null)
            {
                return false;
            }

            m_inProgress = m_msgSource.PullMsg();

            if (m_inProgress == null)
                return false;

            m_inProgress.ResetFlags(MsgFlags.Shared | MsgFlags.More | MsgFlags.Identity);

            NextStep(null, 0, RawMessageSizeReadyState, true);

            return true;
        }
开发者ID:JayShelton,项目名称:netmq,代码行数:25,代码来源:RawEncoder.cs

示例4: XSetSocketOption

        protected override void XSetSocketOption(ZmqSocketOptions option, Object optval)
        {
            if (option != ZmqSocketOptions.Subscribe && option != ZmqSocketOptions.Unsubscribe)
            {
                throw InvalidException.Create();
            }

            byte[] val;

            if (optval is String)
                val =  Encoding.ASCII.GetBytes ((String)optval);
            else if (optval is byte[])
                val = (byte[]) optval;
            else
                throw InvalidException.Create();

            //  Create the subscription message.
            Msg msg = new Msg(val.Length + 1);
            if (option == ZmqSocketOptions.Subscribe)
                msg.Put((byte)1);
            else if (option == ZmqSocketOptions.Unsubscribe)
                msg.Put((byte)0);
            msg.Put (val,1);

            //  Pass it further on in the stack.
            base.XSend (msg, 0);
        }
开发者ID:bubbafat,项目名称:netmq,代码行数:27,代码来源:Sub.cs

示例5: MessageReadySize

        public override bool MessageReadySize(int msgSize)
        {
            m_inProgress = new Msg(msgSize);

              NextStep(m_inProgress.Data, m_inProgress.Size, RawMessageReadyState);

              return true;
        }
开发者ID:hecwow,项目名称:netmq,代码行数:8,代码来源:RawDecoder.cs

示例6: Main

        static int Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("usage: remote_lat remote_lat <connect-to> <message-size> <roundtrip-count>");
                return 1;
            }

            string connectTo = args[0];
            int messageSize = int.Parse(args[1]);
            int roundtripCount = int.Parse(args[2]);

            var context = ZMQ.CtxNew();
            var reqSocket = ZMQ.Socket(context, ZmqSocketType.Req);
            bool connected = reqSocket.Connect(connectTo);
            if (!connected)
            {
                Console.WriteLine("error in zmq_connect");
            }

            var message = new Msg(messageSize);

            var stopWatch = Stopwatch.StartNew();

            for (int i = 0; i != roundtripCount; i++)
            {
                bool sent = reqSocket.Send(message, SendRecieveOptions.None);
                if (!sent)
                {
                    Console.WriteLine("error in zmq_sendmsg");
                    return -1;
                }

                message = reqSocket.Recv(SendRecieveOptions.None);
                if (message.Size != messageSize)
                {
                    Console.WriteLine("message of incorrect size received. Received: " + message.Size + " Expected: " + messageSize);
                    return -1;
                }
            }

            stopWatch.Stop();

            message.Close();

            double elapsedMicroseconds = stopWatch.ElapsedTicks * 1000000 / Stopwatch.Frequency;
            double latency = elapsedMicroseconds / (roundtripCount * 2);

            Console.WriteLine("message size: {0} [B]", messageSize);
            Console.WriteLine("roundtrip count: {0}", roundtripCount);
            Console.WriteLine("average latency: {0:0.000} [µs]", latency);

            reqSocket.Close();
            context.Terminate();

            return 0;
        }
开发者ID:oskarwkarlsson,项目名称:netmq,代码行数:57,代码来源:Program.cs

示例7: XRecv

        protected override bool XRecv(SendReceiveOptions flags, out Msg msg)
        {
            //  Deallocate old content of the message.

            msg = null;
            if (m_pipe == null || (msg = m_pipe.Read ()) == null)
            {
                return false;
            }
            return true;
        }
开发者ID:GianniBortoloBossini,项目名称:netmq,代码行数:11,代码来源:Pair.cs

示例8: XHasIn

        protected override bool XHasIn()
        {
            //  We may already have a message pre-fetched.
            if (m_prefetched)
                return true;

            //  Try to read the next message to the pre-fetch buffer.
            m_prefetchedMsg = xxrecv(SendRecieveOptions.DontWait);
            if (m_prefetchedMsg == null && ZError.IsError(ErrorNumber.EAGAIN))
                return false;
            m_prefetched = true;
            return true;
        }
开发者ID:oskarwkarlsson,项目名称:netmq,代码行数:13,代码来源:Dealer.cs

示例9: XHasIn

        protected override bool XHasIn()
        {
            //  We may already have a message pre-fetched.
            if (m_prefetched)
                return true;

            //  Try to read the next message to the pre-fetch buffer.
            try
            {
                m_prefetchedMsg = xxrecv(SendRecieveOptions.DontWait);
            }
            catch (AgainException ex)
            {
                return false;
            }

            m_prefetched = true;
            return true;
        }
开发者ID:bubbafat,项目名称:netmq,代码行数:19,代码来源:Dealer.cs

示例10: Stream

        public Stream(Ctx parent, int threadId, int sid)
            : base(parent, threadId, sid)
        {
            m_prefetched = false;
              m_identitySent = false;
              m_currentOut = null;
              m_moreOut = false;
              m_nextPeerId = Utils.GenerateRandom();

              m_options.SocketType = ZmqSocketType.Stream;

              m_fq = new FQ();
              m_prefetchedId = new Msg();
              m_prefetchedMsg = new Msg();

              m_outpipes = new Dictionary<Blob, Outpipe>();

              m_options.RawSocket = true;
        }
开发者ID:hecwow,项目名称:netmq,代码行数:19,代码来源:Stream.cs

示例11: XSub

        static XSub()
        {
            s_sendSubscription = (data, size, arg) => {

                                                       	Pipe pipe = (Pipe) arg;

                                                       	//  Create the subsctription message.
                                                       	Msg msg = new Msg(size + 1);
                                                       	msg.Put((byte)1);
                                                       	msg.Put(data,1, size);

                                                       	//  Send it to the pipe.
                                                       	bool sent = pipe.Write (msg);
                                                       	//  If we reached the SNDHWM, and thus cannot send the subscription, drop
                                                       	//  the subscription message instead. This matches the behaviour of
                                                       	//  zmq_setsockopt(ZMQ_SUBSCRIBE, ...), which also drops subscriptions
                                                       	//  when the SNDHWM is reached.
                                                       	if (!sent)
                                                       		msg.Close ();

            };
        }
开发者ID:jasenkin,项目名称:netmq,代码行数:22,代码来源:XSub.cs

示例12: Send

        public static void Send(SocketBase s, byte[] buf, int len, SendReceiveOptions flags)
        {
            if (s == null || !s.CheckTag())
            {
                throw NetMQException.Create(ErrorCode.EFAULT);
            }

            Msg msg = new Msg(len);
            msg.Put(buf, 0, len);

            SendMsg(s, msg, flags);
        }
开发者ID:kamlesh-patel,项目名称:netmq,代码行数:12,代码来源:ZMQ.cs

示例13: MsgSize

 public static int MsgSize(Msg msg)
 {
     return msg.Size;
 }
开发者ID:kamlesh-patel,项目名称:netmq,代码行数:4,代码来源:ZMQ.cs

示例14: MsgGet

 public static int MsgGet(Msg msg)
 {
     return ZmqMsgGet(msg, MsgFlags.More);
 }
开发者ID:kamlesh-patel,项目名称:netmq,代码行数:4,代码来源:ZMQ.cs

示例15: XRecv

        protected override bool XRecv(SendReceiveOptions flags, out Msg msg)
        {
            bool isMessageAvailable;

            //  If we are in middle of sending a reply, we cannot receive next request.
            if (m_sendingReply) {
                throw NetMQException.Create("Cannot receive another request",ErrorCode.EFSM);
                throw new InvalidOperationException();
            }

            //  First thing to do when receiving a request is to copy all the labels
            //  to the reply pipe.
            if (m_requestBegins)
            {
                while (true) {
                    isMessageAvailable = base.XRecv (flags, out msg);

                    if (!isMessageAvailable)
                    {
                        return false;
                    }
                    else if (msg == null)
                    {
                        return true;
                    }

                    if (msg.HasMore) {
                        //  Empty message part delimits the traceback stack.
                        bool bottom = (msg.Size == 0);

                        //  Push it to the reply pipe.
                        isMessageAvailable = base.XSend(msg, flags);
                        if(!isMessageAvailable)
                        {
                            return false;
                        }

                        if (bottom)
                            break;
                    } else {
                        //  If the traceback stack is malformed, discard anything
                        //  already sent to pipe (we're at end of invalid message).
                        base.Rollback();
                    }
                }
                m_requestBegins = false;
            }

            //  Get next message part to return to the user.
            isMessageAvailable = base.XRecv(flags, out msg);

            if (!isMessageAvailable)
            {
                return false;
            }
            else if (msg == null)
            {
                return true;
            }

            //  If whole request is read, flip the FSM to reply-sending state.
            if (!msg.HasMore) {
                m_sendingReply = true;
                m_requestBegins = true;
            }

            return true;
        }
开发者ID:jasenkin,项目名称:netmq,代码行数:68,代码来源:Rep.cs


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