當前位置: 首頁>>代碼示例>>C#>>正文


C# NetMQ.Msg類代碼示例

本文整理匯總了C#中NetMQ.Msg的典型用法代碼示例。如果您正苦於以下問題:C# Msg類的具體用法?C# Msg怎麽用?C# Msg使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Msg類屬於NetMQ命名空間,在下文中一共展示了Msg類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Main

        private 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]);

            using (var context = NetMQContext.Create())
            using (var push = context.CreatePushSocket())
            {
                push.Connect(connectTo);

                for (int i = 0; i != messageCount; i++)
                {
                    var msg = new Msg();
                    msg.InitPool(messageSize);
                    push.Send(ref msg, SendReceiveOptions.None);
                    msg.Close();
                }
            }

            return 0;
        }
開發者ID:wangkai2014,項目名稱:netmq,代碼行數:28,代碼來源:Program.cs

示例2: SendFrame

 /// <summary>
 /// Transmit a byte-array of data over this socket, block until frame is sent.
 /// </summary>
 /// <param name="socket">the IOutgoingSocket to transmit on</param>
 /// <param name="data">the byte-array of data to send</param>
 /// <param name="length">the number of bytes to send from <paramref name="data"/>.</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( this IOutgoingSocket socket,  byte[] data, int length, bool more = false)
 {
     var msg = new Msg();
     msg.InitPool(length);
     Buffer.BlockCopy(data, 0, msg.Data, msg.Offset, length);
     socket.Send(ref msg, more);
     msg.Close();
 }
開發者ID:awb99,項目名稱:netmq,代碼行數:15,代碼來源:OutgoingSocketExtensions.cs

示例3: Send

        public static void Send([NotNull] this IOutgoingSocket socket, [NotNull] byte[] data, int length, SendReceiveOptions options)
        {
            var msg = new Msg();
            msg.InitPool(length);

            Buffer.BlockCopy(data, 0, msg.Data, 0, length);

            socket.Send(ref msg, options);

            msg.Close();
        }
開發者ID:Robin--,項目名稱:netmq,代碼行數:11,代碼來源:OutgoingSocketExtensions.cs

示例4: ReceiveFrameBytes

        public static byte[] ReceiveFrameBytes([NotNull] this IReceivingSocket socket, out bool more)
        {
            var msg = new Msg();
            msg.InitEmpty();

            socket.Receive(ref msg);

            var data = msg.CloneData();

            more = msg.HasMore;

            msg.Close();
            return data;
        }
開發者ID:hdxhan,項目名稱:netmq,代碼行數:14,代碼來源:ReceivingSocketExtensions.cs

示例5: SendFrame

        /// <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();
        }
開發者ID:tobi-tobsen,項目名稱:netmq,代碼行數:22,代碼來源:OutgoingSocketExtensions.cs

示例6: ReceiveMultipartStrings

        public static List<string> ReceiveMultipartStrings([NotNull] this IReceivingSocket socket, [NotNull] Encoding encoding, int expectedFrameCount = 4)
        {
            var frames = new List<string>(expectedFrameCount);

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

            do
            {
                socket.Receive(ref msg);
                frames.Add(encoding.GetString(msg.Data, msg.Offset, msg.Size));
            }
            while (msg.HasMore);

            msg.Close();
            return frames;
        }
開發者ID:hdxhan,項目名稱:netmq,代碼行數:17,代碼來源:ReceivingSocketExtensions.cs

示例7: ReceiveString

        public static string ReceiveString([NotNull] this IReceivingSocket socket, [NotNull] Encoding encoding, SendReceiveOptions options, out bool hasMore)
        {
            if (encoding == null)
                throw new ArgumentNullException("encoding");

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

            socket.Receive(ref msg, options);

            hasMore = msg.HasMore;

            string data = msg.Size > 0
                ? encoding.GetString(msg.Data, msg.Offset, msg.Size)
                : string.Empty;

            msg.Close();
            return data;
        }
開發者ID:hdxhan,項目名稱:netmq,代碼行數:19,代碼來源:ReceivingSocketExtensions.cs

示例8: SkipFrame

 /// <summary>
 /// Receive a single frame from <paramref cref="socket"/>, blocking until one arrives, then ignore its content.
 /// </summary>
 /// <param name="socket">The socket to receive from.</param>
 public static void SkipFrame([NotNull] this IReceivingSocket socket)
 {
     var msg = new Msg();
     msg.InitEmpty();
     socket.Receive(ref msg);
     msg.Close();
 }
開發者ID:hdxhan,項目名稱:netmq,代碼行數:11,代碼來源:ReceivingSocketExtensions.cs

示例9: ReceiveFrameString

        public static string ReceiveFrameString([NotNull] this IReceivingSocket socket, [NotNull] Encoding encoding, out bool more)
        {
            var msg = new Msg();
            msg.InitEmpty();

            socket.Receive(ref msg);

            more = msg.HasMore;

            var str = msg.Size > 0
                ? encoding.GetString(msg.Data, msg.Offset, msg.Size)
                : string.Empty;

            msg.Close();
            return str;
        }
開發者ID:hdxhan,項目名稱:netmq,代碼行數:16,代碼來源:ReceivingSocketExtensions.cs

示例10: TryReceiveFrameString

        /// <summary>
        /// Attempt to receive a single frame from <paramref cref="socket"/>, and decode as a string using <paramref name="encoding"/>.
        /// If no message is available within <paramref name="timeout"/>, return <c>false</c>.
        /// </summary>
        /// <param name="socket">The socket to receive from.</param>
        /// <param name="timeout">The maximum period of time to wait for a message to become available.</param>
        /// <param name="encoding">The encoding used to convert the frame's data to a string.</param>
        /// <param name="frameString">The content of the received message frame as a string, or <c>null</c> if no message was available.</param>
        /// <param name="more"><c>true</c> if another frame of the same message follows, otherwise <c>false</c>.</param>
        /// <returns><c>true</c> if a message was available, otherwise <c>false</c>.</returns>
        public static bool TryReceiveFrameString([NotNull] this IReceivingSocket socket, TimeSpan timeout, [NotNull] Encoding encoding, out string frameString, out bool more)
        {
            var msg = new Msg();
            msg.InitEmpty();

            if (socket.TryReceive(ref msg, timeout))
            {
                more = msg.HasMore;

                frameString = msg.Size > 0
                    ? encoding.GetString(msg.Data, msg.Offset, msg.Size)
                    : string.Empty;

                msg.Close();
                return true;
            }

            frameString = null;
            more = false;
            msg.Close();
            return false;
        }
開發者ID:hdxhan,項目名稱:netmq,代碼行數:32,代碼來源:ReceivingSocketExtensions.cs

示例11: TrySkipFrame

 /// <summary>
 /// Attempt to receive a single frame from <paramref cref="socket"/>, then ignore its content.
 /// If no message is immediately available, return <c>false</c>.
 /// Indicate whether further frames exist via <paramref name="more"/>.
 /// </summary>
 /// <param name="socket">The socket to receive from.</param>
 /// <param name="more"><c>true</c> if another frame of the same message follows, otherwise <c>false</c>.</param>
 /// <returns><c>true</c> if a frame was received and ignored, otherwise <c>false</c>.</returns>
 public static bool TrySkipFrame([NotNull] this IReceivingSocket socket, out bool more)
 {
     var msg = new Msg();
     msg.InitEmpty();
     var result = socket.TryReceive(ref msg, TimeSpan.Zero);
     more = msg.HasMore;
     msg.Close();
     return result;
 }
開發者ID:hdxhan,項目名稱:netmq,代碼行數:17,代碼來源:ReceivingSocketExtensions.cs

示例12: Receive

 /// <summary>
 /// Block until the next message arrives, then make the message's data available via <paramref name="msg"/>.
 /// </summary>
 /// <remarks>
 /// The call  blocks until the next message arrives, and cannot be interrupted. This a convenient and safe when
 /// you know a message is available, such as for code within a <see cref="NetMQSocket.ReceiveReady"/> callback.
 /// </remarks>
 /// <param name="socket">The socket to receive from.</param>
 /// <param name="msg">An object to receive the message's data into.</param>
 public static void Receive(this IReceivingSocket socket, ref Msg msg)
 {
     var result = socket.TryReceive(ref msg, SendReceiveConstants.InfiniteTimeout);
     Debug.Assert(result);
 }
開發者ID:hdxhan,項目名稱:netmq,代碼行數:14,代碼來源:ReceivingSocketExtensions.cs

示例13: TrySendFrame

        /// <summary>
        /// Attempt to transmit a single frame on <paramref cref="socket"/>.
        /// If message cannot be sent within <paramref name="timeout"/>, return <c>false</c>.
        /// </summary>
        /// <param name="socket">the IOutgoingSocket to transmit on</param>
        /// <param name="timeout">The maximum period of time to try to send a message.</param>
        /// <param name="data">the byte-array of data to send</param>        
        /// <param name="length">the number of bytes to send from <paramref name="data"/>.</param>
        /// <param name="more">set this flag to true to signal that you will be immediately sending another frame (optional: default is false)</param>
        /// <returns><c>true</c> if a message was available, otherwise <c>false</c>.</returns>
        public static bool TrySendFrame([NotNull] this IOutgoingSocket socket, TimeSpan timeout, [NotNull] byte[] data, int length, bool more = false)
        {
            var msg = new Msg();
            msg.InitPool(length);
            Buffer.BlockCopy(data, 0, msg.Data, 0, length);

            if (!socket.TrySend(ref msg, timeout, more))
            {
                msg.Close();
                return false;
            }

            msg.Close();
            return true;
        }
開發者ID:Robin--,項目名稱:netmq,代碼行數:25,代碼來源:OutgoingSocketExtensions.cs

示例14: TrySkipMultipartMessage

 /// <summary>
 /// Attempt to receive all frames of the next message from <paramref cref="socket"/>, then ignore their contents.
 /// If no message is immediately available, return <c>false</c>.
 /// </summary>
 /// <param name="socket">The socket to receive from.</param>
 /// <returns><c>true</c> if a frame was received and ignored, otherwise <c>false</c>.</returns>
 public static bool TrySkipMultipartMessage([NotNull] this IReceivingSocket socket)
 {
     var msg = new Msg();
     msg.InitEmpty();
     var received = socket.TryReceive(ref msg, TimeSpan.Zero);
     msg.Close();
     return received;
 }
開發者ID:hdxhan,項目名稱:netmq,代碼行數:14,代碼來源:ReceivingSocketExtensions.cs

示例15: Signal

        /// <summary>
        /// Transmit a status-signal over this socket.
        /// </summary>
        /// <param name="socket">the IOutgoingSocket to transmit on</param>
        /// <param name="status">a byte that contains the status signal to send</param>
        private static void Signal([NotNull] this IOutgoingSocket socket, byte status)
        {
            long signalValue = 0x7766554433221100L + status;

            Msg msg = new Msg();
            msg.InitPool(8);
            NetworkOrderBitsConverter.PutInt64(signalValue, msg.Data);

            socket.Send(ref msg, false);

            msg.Close();
        }
開發者ID:Robin--,項目名稱:netmq,代碼行數:17,代碼來源:OutgoingSocketExtensions.cs


注:本文中的NetMQ.Msg類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。