예제 #1
0
        /// <summary>
        /// Transmit a string over this socket, block until frame is sent.
        /// </summary>
        /// <param name="socket">the IOutgoingSocket to transmit on</param>
        /// <param name="message">the string to send</param>
        /// <param name="more">set this flag to true to signal that you will be immediately sending another frame (optional: default is false)</param>
        public static void SendFrame([NotNull] this IOutgoingSocket socket, [NotNull] string message, bool more = false)
        {
            var msg = new Msg();

            // Count the number of bytes required to encode the string.
            // Note that non-ASCII strings may not have an equal number of characters
            // and bytes. The encoding must be queried for this answer.
            // With this number, request a buffer from the pool.
            msg.InitPool(SendReceiveConstants.DefaultEncoding.GetByteCount(message));

            // Encode the string into the buffer
            SendReceiveConstants.DefaultEncoding.GetBytes(message, 0, message.Length, msg.Data, 0);

            socket.Send(ref msg, more);
            msg.Close();
        }
예제 #2
0
        public static void Send([NotNull] this IOutgoingSocket socket, [NotNull] byte[] data, int length, bool dontWait = false, bool sendMore = false)
        {
            var options = SendReceiveOptions.None;

            if (dontWait)
            {
                options |= SendReceiveOptions.DontWait;
            }

            if (sendMore)
            {
                options |= SendReceiveOptions.SendMore;
            }

            socket.Send(data, length, options);
        }
예제 #3
0
        public static void Send([NotNull] this IOutgoingSocket socket, [NotNull] string message, [NotNull] Encoding encoding, bool dontWait = false, bool sendMore = false)
        {
            var options = SendReceiveOptions.None;

            if (dontWait)
            {
                options |= SendReceiveOptions.DontWait;
            }

            if (sendMore)
            {
                options |= SendReceiveOptions.SendMore;
            }

            socket.Send(message, encoding, options);
        }
예제 #4
0
        private static void ForwardTo(NetMQSocketEventArgs args, IOutgoingSocket toSocket)
        {
            var msg = new Msg();
            msg.InitEmpty();

            bool more;
            do
            {
                args.Socket.Receive(ref msg);
                more = msg.HasMore;
                toSocket.Send(ref msg, more);
            }
            while (more);

            msg.Close();
        }
예제 #5
0
        public static void Send(this IOutgoingSocket socket, string message, Encoding encoding, SendReceiveOptions options)
        {
            var msg = new Msg();

            // Count the number of bytes required to encode the string.
            // Note that non-ASCII strings may not have an equal number of characters
            // and bytes. The encoding must be queried for this answer.
            // With this number, request a buffer from the pool.
            msg.InitPool(encoding.GetByteCount(message));

            // Encode the string into the buffer
            encoding.GetBytes(message, 0, message.Length, msg.Data, 0);

            socket.Send(ref msg, options);

            msg.Close();
        }
예제 #6
0
        private static void ForwardTo(NetMQSocketEventArgs args, IOutgoingSocket toSocket)
        {
            var msg = new Msg();

            msg.InitEmpty();

            bool more;

            do
            {
                args.Socket.Receive(ref msg);
                more = msg.HasMore;
                toSocket.Send(ref msg, more);
            }while (more);

            msg.Close();
        }
예제 #7
0
        /// <summary>
        /// 将所有消息帧原封不动的发送至另外一端
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="control"></param>
        private static void ProxyBetween(IReceivingSocket from, IOutgoingSocket to, IOutgoingSocket control)
        {
            Msg msg = default(Msg);

            msg.InitEmpty();
            Msg msg2 = default(Msg);

            msg2.InitEmpty();
            bool hasMore;

            do
            {
                from.Receive(ref msg);
                hasMore = msg.HasMore;
                if (control != null)
                {
                    msg2.Copy(ref msg);
                    control.Send(ref msg2, hasMore);
                }
                to.Send(ref msg, hasMore);
            }while (hasMore);
            msg2.Close();
            msg.Close();
        }
예제 #8
0
        /// <summary>
        /// Send the ZreMsg 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
                var more = Id == MessageId.Whisper || Id == MessageId.Shout;
                output.Send(ref msg, 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.SendMultipartMessage(Whisper.Content);
                    break;

                case MessageId.Shout:
                    if (Shout.Content == null)
                    {
                        Shout.Content = new NetMQMessage();
                        Shout.Content.PushEmptyFrame();
                    }
                    output.SendMultipartMessage(Shout.Content);
                    break;
                }
            }
            finally
            {
                m_buffer = null;
                msg.Close();
            }
        }
 public static IOutgoingSocket SendMore([NotNull] this IOutgoingSocket socket, [NotNull] string message, [NotNull] Encoding encoding, bool dontWait = false)
 {
     socket.Send(message, encoding, dontWait, true);
     return(socket);
 }
예제 #10
0
		/// <summary>
		/// Send the Codec 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.Message:
					frameSize += Message.GetFrameSize();
					break;
				case MessageId.ServiceRegister:
					frameSize += ServiceRegister.GetFrameSize();
					break;
				case MessageId.Error:
					frameSize += Error.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 | 0);

				// put message id
				PutNumber1((byte)Id);
	
				switch (Id) 
				{
					case MessageId.Message:
						Message.Write(this);
					break;
					case MessageId.ServiceRegister:
						ServiceRegister.Write(this);
					break;
					case MessageId.Error:
						Error.Write(this);
					break;
				}

				//  Send the data frame				
				output.Send(ref msg, false);       
			}
			finally
			{
				m_buffer = null;
				msg.Close();
			}
		}	
 public static void Send([NotNull] this IOutgoingSocket socket, [NotNull] byte[] data)
 {
     socket.Send(data, data.Length);
 }
 public static IOutgoingSocket SendMore([NotNull] this IOutgoingSocket socket, [NotNull] byte[] data, int length, bool dontWait = false)
 {
     socket.Send(data, length, dontWait, true);
     return(socket);
 }
예제 #13
0
 public static IOutgoingSocket SendMore(this IOutgoingSocket socket, byte[] data, bool dontWait = false)
 {
     socket.Send(data, data.Length, dontWait, true);
     return(socket);
 }
예제 #14
0
 public static void Send(this IOutgoingSocket socket, byte[] data)
 {
     socket.Send(data, data.Length);
 }
예제 #15
0
 public static void Send(this IOutgoingSocket socket, string message, bool dontWait = false, bool sendMore = false)
 {
     byte[] data = Encoding.ASCII.GetBytes(message);
     socket.Send(data, data.Length, dontWait, sendMore);
 }
예제 #16
0
 public static IOutgoingSocket SendMore(this IOutgoingSocket socket, string message, bool dontWait = false)
 {
     socket.Send(message, false, true);
     return(socket);
 }
예제 #17
0
파일: Proxy.cs 프로젝트: somdoron/netmq
        private static void ProxyBetween(IReceivingSocket from, IOutgoingSocket to, [CanBeNull] IOutgoingSocket 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();
        }
예제 #18
0
        /// <summary>
        /// Send the Example 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.Log:
                frameSize += Log.GetFrameSize();
                break;

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

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

            case MessageId.Types:
                frameSize += Types.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 | 0);

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

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

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

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

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

                //  Send the data frame
                output.Send(ref msg, false);
            }
            finally
            {
                m_buffer = null;
                msg.Close();
            }
        }
예제 #19
0
        /// <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();
            }
        }
예제 #20
0
파일: Codec.cs 프로젝트: yh-test/NetMQ.High
        /// <summary>
        /// Send the Codec 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.Message:
                frameSize += Message.GetFrameSize();
                break;

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

            case MessageId.Error:
                frameSize += Error.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 | 0);

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

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

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

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

                //  Send the data frame
                output.Send(ref msg, false);
            }
            finally
            {
                m_buffer = null;
                msg.Close();
            }
        }
예제 #21
0
파일: Example.cs 프로젝트: jonefmc/zproto
        /// <summary>
        /// Send the Example to the socket.
        /// </summary>
        public void Send(IOutgoingSocket output)
        {
            if (output is RouterSocket)
                output.SendMore(RoutingId);

            int frameSize = 2 + 1;          //  Signature and message ID
            switch (Id)
            {
                case MessageId.Log:
                    frameSize += 2;            //  Sequence
                    frameSize += 2;            //  Version
                    frameSize += 1;            //  Level
                    frameSize += 1;            //  Event
                    frameSize += 2;            //  Node
                    frameSize += 2;            //  Peer
                    frameSize += 8;            //  Time
                    frameSize += 1 + Host.Length;
                    frameSize += 4;
                    if (Data != null)
                        frameSize += Data.Length;
                    break;
                case MessageId.Structures:
                    frameSize += 2;            //  Sequence
                    frameSize += 4;            //  Size is 4 octets
                    if (Aliases != null)
                    {
                        foreach(string s in Aliases)
                        {
                            frameSize += 4 + s.Length;
                        }
                    }
                    frameSize += 4;            //  Size is 4 octets
                    if (Headers != null)
                    {
                        int headersSize = 0;

                        foreach (var pair in Headers)
                        {
                            headersSize += 1 + pair.Key.Length;
                            headersSize += 4 + pair.Value.Length;
                        }

                        frameSize += headersSize;
                    }

                    break;
                case MessageId.Binary:
                    frameSize += 2;            //  Sequence
                    frameSize += 4;            //  Flags
                    frameSize += 4;            //  Size is 4 octets
                    if (PublicKey != null)
                        frameSize += PublicKey.Length;
                    frameSize  += 16;    //  Identifier
                    break;
                case MessageId.Types:
                    frameSize += 2;            //  Sequence
                    frameSize += 1 + ClientForename.Length;
                    frameSize += 1 + ClientSurname.Length;
                    frameSize += 1 + ClientMobile.Length;
                    frameSize += 1 + ClientEmail.Length;
                    frameSize += 1 + SupplierForename.Length;
                    frameSize += 1 + SupplierSurname.Length;
                    frameSize += 1 + SupplierMobile.Length;
                    frameSize += 1 + SupplierEmail.Length;
                    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 | 0);

                // put message id
                PutNumber1((byte)Id);
                bool sendContent = false;
                int frames = 1;              //  Total number of frames to send

                switch (Id)
                {
                    case MessageId.Log:
                        PutNumber2(Sequence);
                        PutNumber2(3); // Version
                        PutNumber1(Level);
                        PutNumber1(Event);
                        PutNumber2(Node);
                        PutNumber2(Peer);
                        PutNumber8(Time);
                        PutString(Host);
                        if (Data != null)
                            PutLongString(Data);
                        else
                            PutNumber4(0);    //  Empty string
                    break;
                    case MessageId.Structures:
                        PutNumber2(Sequence);

                        if (Aliases != null)
                        {
                            PutNumber4((UInt32)Aliases.Count);

                            foreach (string s in Aliases)
                            {
                                PutLongString(s);
                            }
                        }
                        else
                            PutNumber4(0);    //  Empty string array

                        if (Headers != null)
                        {
                            PutNumber4((UInt32)Headers.Count);

                            foreach(var pair in Headers)
                            {
                                PutString(pair.Key);
                                PutLongString(pair.Value);
                            }
                        }
                        else
                            PutNumber4(0);    //  Empty dictionary

                    break;
                    case MessageId.Binary:
                        PutNumber2(Sequence);
                        PutOctets(Flags, 4);

                        if (PublicKey != null)
                        {
                            PutNumber4((UInt32)PublicKey.Length);
                            Buffer.BlockCopy(PublicKey, 0, m_buffer, m_offset, PublicKey.Length);
                            m_offset += PublicKey.Length;
                        }
                        else
                            PutNumber4(0);    //  Empty chunk

                        // copy guid
                        Buffer.BlockCopy(Identifier.ToByteArray(), 0, m_buffer, m_offset, 16);
                        m_offset += 16;
                        frames++;
                        frames += Content != null ? Content.FrameCount : 1;
                        sendContent = true;
                    break;
                    case MessageId.Types:
                        PutNumber2(Sequence);
                        PutString(ClientForename);
                        PutString(ClientSurname);
                        PutString(ClientMobile);
                        PutString(ClientEmail);
                        PutString(SupplierForename);
                        PutString(SupplierSurname);
                        PutString(SupplierMobile);
                        PutString(SupplierEmail);
                    break;
                }

                //  Now send the data frame
                output.Send(ref msg, --frames == 0 ? SendReceiveOptions.None : SendReceiveOptions.SendMore);

                //  Now send any frame fields, in order
                if (Id == MessageId.Binary)
                {
                    if (--frames == 0)
                        output.Send(Address != null ? Address : new byte[0]);
                    else
                        output.SendMore(Address != null ? Address : new byte[0]);
                }

                //  Now send the Content if necessary
                if (sendContent)
                {
                    if (Content != null)
                    {
                        output.SendMessage(Content);
                    }
                    else
                        output.Send(new byte[0]);
                }
            }
            finally
            {
                m_buffer = null;
                msg.Close();
            }
        }
예제 #22
0
파일: Example.cs 프로젝트: xaqq/zproto
        /// <summary>
        /// Send the Example to the socket.
        /// </summary>
        public void Send(IOutgoingSocket output)
        {
            if (output is RouterSocket)
            {
                output.SendMore(RoutingId);
            }

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

            switch (Id)
            {
            case MessageId.Log:
                frameSize += 2;                                    //  Sequence
                frameSize += 2;                                    //  Version
                frameSize += 1;                                    //  Level
                frameSize += 1;                                    //  Event
                frameSize += 2;                                    //  Node
                frameSize += 2;                                    //  Peer
                frameSize += 8;                                    //  Time
                frameSize += 1 + Host.Length;
                frameSize += 4;
                if (Data != null)
                {
                    frameSize += Data.Length;
                }
                break;

            case MessageId.Structures:
                frameSize += 2;                                    //  Sequence
                frameSize += 4;                                    //  Size is 4 octets
                if (Aliases != null)
                {
                    foreach (string s in Aliases)
                    {
                        frameSize += 4 + s.Length;
                    }
                }
                frameSize += 4;                                    //  Size is 4 octets
                if (Headers != null)
                {
                    int headersSize = 0;

                    foreach (var pair in Headers)
                    {
                        headersSize += 1 + pair.Key.Length;
                        headersSize += 4 + pair.Value.Length;
                    }

                    frameSize += headersSize;
                }

                break;

            case MessageId.Binary:
                frameSize += 2;                                    //  Sequence
                frameSize += 4;                                    //  Flags
                frameSize += 4;                                    //  Size is 4 octets
                if (PublicKey != null)
                {
                    frameSize += PublicKey.Length;
                }
                frameSize += 16;                             //  Identifier
                break;

            case MessageId.Types:
                frameSize += 2;                                    //  Sequence
                frameSize += 1 + ClientForename.Length;
                frameSize += 1 + ClientSurname.Length;
                frameSize += 1 + ClientMobile.Length;
                frameSize += 1 + ClientEmail.Length;
                frameSize += 1 + SupplierForename.Length;
                frameSize += 1 + SupplierSurname.Length;
                frameSize += 1 + SupplierMobile.Length;
                frameSize += 1 + SupplierEmail.Length;
                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 | 0);

                // put message id
                PutNumber1((byte)Id);
                bool sendContent = false;
                int  frames      = 1;                        //  Total number of frames to send

                switch (Id)
                {
                case MessageId.Log:
                    PutNumber2(Sequence);
                    PutNumber2(3);                             // Version
                    PutNumber1(Level);
                    PutNumber1(Event);
                    PutNumber2(Node);
                    PutNumber2(Peer);
                    PutNumber8(Time);
                    PutString(Host);
                    if (Data != null)
                    {
                        PutLongString(Data);
                    }
                    else
                    {
                        PutNumber4(0);                                    //  Empty string
                    }
                    break;

                case MessageId.Structures:
                    PutNumber2(Sequence);

                    if (Aliases != null)
                    {
                        PutNumber4((UInt32)Aliases.Count);

                        foreach (string s in Aliases)
                        {
                            PutLongString(s);
                        }
                    }
                    else
                    {
                        PutNumber4(0);                                    //  Empty string array
                    }
                    if (Headers != null)
                    {
                        PutNumber4((UInt32)Headers.Count);

                        foreach (var pair in Headers)
                        {
                            PutString(pair.Key);
                            PutLongString(pair.Value);
                        }
                    }
                    else
                    {
                        PutNumber4(0);                                    //  Empty dictionary
                    }
                    break;

                case MessageId.Binary:
                    PutNumber2(Sequence);
                    PutOctets(Flags, 4);

                    if (PublicKey != null)
                    {
                        PutNumber4((UInt32)PublicKey.Length);
                        Buffer.BlockCopy(PublicKey, 0, m_buffer, m_offset, PublicKey.Length);
                        m_offset += PublicKey.Length;
                    }
                    else
                    {
                        PutNumber4(0);                                    //  Empty chunk
                    }
                    // copy guid
                    Buffer.BlockCopy(Identifier.ToByteArray(), 0, m_buffer, m_offset, 16);
                    m_offset += 16;
                    frames++;
                    frames     += Content != null ? Content.FrameCount : 1;
                    sendContent = true;
                    break;

                case MessageId.Types:
                    PutNumber2(Sequence);
                    PutString(ClientForename);
                    PutString(ClientSurname);
                    PutString(ClientMobile);
                    PutString(ClientEmail);
                    PutString(SupplierForename);
                    PutString(SupplierSurname);
                    PutString(SupplierMobile);
                    PutString(SupplierEmail);
                    break;
                }

                //  Now send the data frame
                output.Send(ref msg, --frames == 0 ? SendReceiveOptions.None : SendReceiveOptions.SendMore);

                //  Now send any frame fields, in order
                if (Id == MessageId.Binary)
                {
                    if (--frames == 0)
                    {
                        output.Send(Address != null ? Address : new byte[0]);
                    }
                    else
                    {
                        output.SendMore(Address != null ? Address : new byte[0]);
                    }
                }

                //  Now send the Content if necessary
                if (sendContent)
                {
                    if (Content != null)
                    {
                        output.SendMessage(Content);
                    }
                    else
                    {
                        output.Send(new byte[0]);
                    }
                }
            }
            finally
            {
                m_buffer = null;
                msg.Close();
            }
        }
예제 #23
0
		/// <summary>
		/// Send the ZreMsg 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();
			}
		}