本文整理汇总了C#中ZSocket.SendFrame方法的典型用法代码示例。如果您正苦于以下问题:C# ZSocket.SendFrame方法的具体用法?C# ZSocket.SendFrame怎么用?C# ZSocket.SendFrame使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZSocket
的用法示例。
在下文中一共展示了ZSocket.SendFrame方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Tripping_ClientTask
static void Tripping_ClientTask(ZContext ctx, ZSocket pipe, CancellationTokenSource cancellor, object[] args)
{
using (ZSocket client = new ZSocket(ctx, ZSocketType.DEALER))
{
client.Connect("tcp://localhost:5555");
"Setting up test...".DumpString();
Thread.Sleep(100);
int requests;
"Synchronous round-trip test...".DumpString();
var start = DateTime.Now;
Stopwatch sw = Stopwatch.StartNew();
for (requests = 0; requests < 10000; requests++)
{
using (var outgoing = new ZFrame("hello"))
{
client.Send(outgoing);
using (var reply = client.ReceiveFrame())
{
if (Verbose)
reply.ToString().DumpString();
}
}
}
sw.Stop();
" {0} calls - {1} ms => {2} calls / second".DumpString(requests, sw.ElapsedMilliseconds, requests * 1000 / sw.ElapsedMilliseconds);
"Asynchronous round-trip test...".DumpString();
sw.Restart();
// sending 100000 requests => often ends in eagain exception in ZContext.Proxy!!
for (requests = 0; requests < 1000; requests++)
using (var outgoing = new ZFrame("hello"))
client.SendFrame(outgoing);
for (requests = 0; requests < 1000; requests++)
using (var reply = client.ReceiveFrame())
if (Verbose)
reply.ToString().DumpString();
sw.Stop();
" {0} calls - {1} ms => {2} calls / second".DumpString(requests, sw.ElapsedMilliseconds, requests * 1000 / sw.ElapsedMilliseconds);
using (var outgoing = new ZFrame("done"))
pipe.SendFrame(outgoing);
}
}
示例2: Espresso0_Publisher
static void Espresso0_Publisher(ZContext context)
{
// The publisher sends random messages starting with A-J:
using (var publisher = new ZSocket(context, ZSocketType.PUB))
{
publisher.Bind("tcp://*:6000");
var rnd = new Random();
ZError error;
while (true)
{
var s = String.Format("{0}-{1,0:D5}", (char)(rnd.Next(10) + 'A'), rnd.Next(100000));
if (!publisher.SendFrame(new ZFrame(s), out error))
{
if (error == ZError.ETERM)
return; // Interrupted
throw new ZException(error);
}
Thread.Sleep(100); // Wait for 1/10th second
}
}
}
示例3: Espresso_Publisher
static void Espresso_Publisher(ZContext context)
{
// The publisher sends random messages starting with A-J:
using (var publisher = new ZSocket(context, ZSocketType.PUB))
{
publisher.Bind("tcp://*:6000");
ZError error;
while (true)
{
var frame = ZFrame.Create(8);
var bytes = new byte[8];
using (var rng = new System.Security.Cryptography.RNGCryptoServiceProvider())
{
rng.GetBytes(bytes);
}
frame.Write(bytes, 0, 8);
if (!publisher.SendFrame(frame, out error))
{
if (error == ZError.ETERM)
return; // Interrupted
throw new ZException(error);
}
Thread.Sleep(1);
}
}
}