/// <summary>
        /// Send the ZreMsgOriginal to the socket.
        /// </summary>
        public void Send(IOutgoingSocket output)
        {
            if (output is RouterSocket)
            {
                output.SendMoreFrame(RoutingId);
            }

            int frameSize = 2 + 1;                      //  Signature and message ID

            switch (Id)
            {
            case MessageId.Hello:
                frameSize += Hello.GetFrameSize();
                break;

            case MessageId.Whisper:
                frameSize += Whisper.GetFrameSize();
                break;

            case MessageId.Shout:
                frameSize += Shout.GetFrameSize();
                break;

            case MessageId.Join:
                frameSize += Join.GetFrameSize();
                break;

            case MessageId.Leave:
                frameSize += Leave.GetFrameSize();
                break;

            case MessageId.Ping:
                frameSize += Ping.GetFrameSize();
                break;

            case MessageId.PingOk:
                frameSize += PingOk.GetFrameSize();
                break;
            }

            //  Now serialize message into the buffer
            Msg msg = new Msg();

            msg.InitPool(frameSize);

            try
            {
                m_offset = 0;
                m_buffer = msg.Data;

                // put signature
                PutNumber2(0xAAA0 | 1);

                // put message id
                PutNumber1((byte)Id);

                switch (Id)
                {
                case MessageId.Hello:
                    Hello.Write(this);
                    break;

                case MessageId.Whisper:
                    Whisper.Write(this);
                    break;

                case MessageId.Shout:
                    Shout.Write(this);
                    break;

                case MessageId.Join:
                    Join.Write(this);
                    break;

                case MessageId.Leave:
                    Leave.Write(this);
                    break;

                case MessageId.Ping:
                    Ping.Write(this);
                    break;

                case MessageId.PingOk:
                    PingOk.Write(this);
                    break;
                }

                //  Send the data frame
                output.Send(ref msg, false);
            }
            finally
            {
                m_buffer = null;
                msg.Close();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Send the ZreMsg to the socket.
        /// Warning re WHISPER and SHOUT: The 0MQ spec http://rfc.zeromq.org/spec:36
        ///     says "message content defined as one 0MQ frame. ZRE does not support multi-frame message contents."
        /// </summary>
        public void Send(IOutgoingSocket output)
        {
            if (output is RouterSocket)
            {
                output.SendMoreFrame(RoutingId);
            }

            int frameSize = 2 + 1; //  Signature and message ID

            switch (Id)
            {
            case MessageId.Hello:
                frameSize += Hello.GetFrameSize();
                break;

            case MessageId.Whisper:
                frameSize += Whisper.GetFrameSize();
                break;

            case MessageId.Shout:
                frameSize += Shout.GetFrameSize();
                break;

            case MessageId.Join:
                frameSize += Join.GetFrameSize();
                break;

            case MessageId.Leave:
                frameSize += Leave.GetFrameSize();
                break;

            case MessageId.Ping:
                frameSize += Ping.GetFrameSize();
                break;

            case MessageId.PingOk:
                frameSize += PingOk.GetFrameSize();
                break;
            }

            //  Now serialize message into the buffer
            Msg msg = new Msg();

            msg.InitPool(frameSize);

            try
            {
                m_offset = 0;
                m_buffer = msg.Data;

                // put signature
                PutNumber2(0xAAA0 | 1);

                // put message id
                PutNumber1((byte)Id);

                switch (Id)
                {
                case MessageId.Hello:
                    Hello.Write(this);
                    break;

                case MessageId.Whisper:
                    Whisper.Write(this);
                    break;

                case MessageId.Shout:
                    Shout.Write(this);
                    break;

                case MessageId.Join:
                    Join.Write(this);
                    break;

                case MessageId.Leave:
                    Leave.Write(this);
                    break;

                case MessageId.Ping:
                    Ping.Write(this);
                    break;

                case MessageId.PingOk:
                    PingOk.Write(this);
                    break;
                }

                //  Send the data frame
                var more = Id == MessageId.Whisper || Id == MessageId.Shout;
                output.TrySend(ref msg, TimeSpan.Zero, more);

                // Send message content for types with content
                switch (Id)
                {
                case MessageId.Whisper:
                    if (Whisper.Content == null)
                    {
                        Whisper.Content = new NetMQMessage();
                        Whisper.Content.PushEmptyFrame();
                    }
                    output.TrySendMultipartMessage(Whisper.Content);
                    break;

                case MessageId.Shout:
                    if (Shout.Content == null)
                    {
                        Shout.Content = new NetMQMessage();
                        Shout.Content.PushEmptyFrame();
                    }
                    output.TrySendMultipartMessage(Shout.Content);
                    break;
                }
            }
            finally
            {
                m_buffer = null;
                msg.Close();
            }
        }