本文整理汇总了C#中NetMQ.Msg.InitEmpty方法的典型用法代码示例。如果您正苦于以下问题:C# Msg.InitEmpty方法的具体用法?C# Msg.InitEmpty怎么用?C# Msg.InitEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetMQ.Msg
的用法示例。
在下文中一共展示了Msg.InitEmpty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
private static int Main(string[] args)
{
if (args.Length != 3)
{
Console.WriteLine("usage: local_thr <bind-to> <message-size> <message-count>");
return 1;
}
string bindTo = args[0];
int messageSize = int.Parse(args[1]);
int messageCount = int.Parse(args[2]);
using (var context = NetMQContext.Create())
using (var pullSocket = context.CreatePullSocket())
{
pullSocket.Bind(bindTo);
var message = new Msg();
message.InitEmpty();
pullSocket.Receive(ref message, SendReceiveOptions.None);
var stopWatch = Stopwatch.StartNew();
for (int i = 0; i != messageCount - 1; i++)
{
pullSocket.Receive(ref message, SendReceiveOptions.None);
if (message.Size != messageSize)
{
Console.WriteLine("message of incorrect size received. Received: " + message.Size + " Expected: " + messageSize);
return -1;
}
}
stopWatch.Stop();
var millisecondsElapsed = stopWatch.ElapsedMilliseconds;
if (millisecondsElapsed == 0)
millisecondsElapsed = 1;
message.Close();
double messagesPerSecond = (double)messageCount/millisecondsElapsed*1000;
double megabits = messagesPerSecond*messageSize*8/1000000;
Console.WriteLine("message size: {0} [B]", messageSize);
Console.WriteLine("message count: {0}", messageCount);
Console.WriteLine("mean throughput: {0:0.000} [msg/s]", messagesPerSecond);
Console.WriteLine("mean throughput: {0:0.000} [Mb/s]", megabits);
pullSocket.Close();
}
return 0;
}
示例2: 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;
}
示例3: Receive
public static byte[] Receive([NotNull] this IReceivingSocket socket, SendReceiveOptions options, out bool hasMore)
{
var msg = new Msg();
msg.InitEmpty();
socket.Receive(ref msg, options);
var data = msg.CloneData();
hasMore = msg.HasMore;
msg.Close();
return data;
}
示例4: Main
private static int Main(string[] args)
{
if (args.Length != 3)
{
Console.WriteLine("usage: local_lat <bind-to> <message-size> <roundtrip-count>");
return 1;
}
string bindTo = args[0];
int messageSize = int.Parse(args[1]);
int roundtripCount = int.Parse(args[2]);
using (var context = NetMQContext.Create())
using (var rep = context.CreateResponseSocket())
{
rep.Bind(bindTo);
var msg = new Msg();
msg.InitEmpty();
for (int i = 0; i != roundtripCount; i++)
{
rep.Receive(ref msg);
if (msg.Size != messageSize)
{
Console.WriteLine("message of incorrect size received. Received: " + msg.Size + " Expected: " + messageSize);
return -1;
}
rep.Send(ref msg, SendReceiveOptions.None);
}
msg.Close();
}
return 0;
}
示例5: TrySkipFrame
/// <summary>
/// Attempt to receive a single frame from <paramref cref="socket"/>, then ignore its content.
/// 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>
/// <returns><c>true</c> if a frame was received and ignored, otherwise <c>false</c>.</returns>
public static bool TrySkipFrame([NotNull] this IReceivingSocket socket, TimeSpan timeout)
{
var msg = new Msg();
msg.InitEmpty();
var received = socket.TryReceive(ref msg, timeout);
msg.Close();
return received;
}
示例6: TrySkipFrame
/// <summary>
/// Attempt to receive a single frame from <paramref name="socket"/>, then ignore its content.
/// 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 TrySkipFrame( this IReceivingSocket socket)
{
var msg = new Msg();
msg.InitEmpty();
var received = socket.TryReceive(ref msg, TimeSpan.Zero);
msg.Close();
return received;
}
示例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: 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;
}
示例9: ReceiveMultipartBytes
/// <summary>
/// Receive all frames of the next message from <paramref cref="socket"/>, blocking until a message arrives.
/// </summary>
/// <param name="socket">The socket to receive from.</param>
/// <param name="frames">Reference to a list for return values. If <c>null</c> a new instance will be assigned, otherwise the provided list will be cleared and populated.</param>
/// <param name="expectedFrameCount">Optional initial <see cref="List{T}.Capacity"/> for the returned <see cref="List{T}"/>.</param>
public static void ReceiveMultipartBytes([NotNull] this IReceivingSocket socket, ref List<byte[]> frames, int expectedFrameCount = 4)
{
if (frames == null)
frames = new List<byte[]>(expectedFrameCount);
else
frames.Clear();
var msg = new Msg();
msg.InitEmpty();
do
{
socket.Receive(ref msg);
frames.Add(msg.CloneData());
}
while (msg.HasMore);
msg.Close();
}
示例10: 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;
}
示例11: ReceiveMessage
public static void ReceiveMessage([NotNull] this IReceivingSocket socket, [NotNull] NetMQMessage message, bool dontWait = false)
{
message.Clear();
var msg = new Msg();
msg.InitEmpty();
do
{
socket.Receive(ref msg, dontWait ? SendReceiveOptions.DontWait : SendReceiveOptions.None);
message.Append(msg.CloneData());
}
while (msg.HasMore);
msg.Close();
}
示例12: TryReceiveMultipartMessage
/// <summary>
/// Attempt to receive all frames of the next message from <paramref cref="socket"/>.
/// 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="message">The received message. Untouched if no message was available.</param>
/// <param name="expectedFrameCount">Specifies the initial capacity of the <see cref="List{T}"/> used
/// to buffer results. If the number of frames is known, set it here. If more frames arrive than expected,
/// an extra allocation will occur, but the result will still be correct.</param>
/// <returns><c>true</c> if a message was available, otherwise <c>false</c>.</returns>
public static bool TryReceiveMultipartMessage([NotNull] this IReceivingSocket socket, TimeSpan timeout, [CanBeNull] ref NetMQMessage message, int expectedFrameCount = 4)
{
var msg = new Msg();
msg.InitEmpty();
// Try to read the first frame
if (!socket.TryReceive(ref msg, timeout))
{
msg.Close();
return false;
}
// We have one, so prepare the container
if (message == null)
message = new NetMQMessage(expectedFrameCount);
else
message.Clear();
// Add the frame
message.Append(new NetMQFrame(msg.CloneData()));
// Rinse and repeat...
while (msg.HasMore)
{
socket.Receive(ref msg);
message.Append(new NetMQFrame(msg.CloneData()));
}
msg.Close();
return true;
}
示例13: ReceiveMultipartMessage
public static NetMQMessage ReceiveMultipartMessage([NotNull] this IReceivingSocket socket, int expectedFrameCount = 4)
{
var msg = new Msg();
msg.InitEmpty();
var message = new NetMQMessage(expectedFrameCount);
do
{
socket.Receive(ref msg);
message.Append(msg.CloneData());
}
while (msg.HasMore);
msg.Close();
return message;
}
示例14: Move
/// <summary>
/// Close this Msg and make it reference the given source Msg, and then clear the Msg to empty.
/// </summary>
/// <param name="src">the source-Msg to become</param>
public void Move(ref Msg src)
{
// Check the validity of the source.
if (!src.IsInitialised)
throw new FaultException("Cannot move an uninitialised Msg.");
if (IsInitialised)
Close();
this = src;
src.InitEmpty();
}
示例15: ProxyBetween
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();
}