本文整理汇总了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;
}
示例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();
}
示例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();
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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();
}