本文整理汇总了C#中ZSocket.ReceiveBytes方法的典型用法代码示例。如果您正苦于以下问题:C# ZSocket.ReceiveBytes方法的具体用法?C# ZSocket.ReceiveBytes怎么用?C# ZSocket.ReceiveBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZSocket
的用法示例。
在下文中一共展示了ZSocket.ReceiveBytes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TaskWorker
public TaskWorker(string workerid="*",string SenderIP = "127.0.0.1", int SenderPort = 5557, string sinkIP = "127.0.0.1", int sinkPort=5558)
{
//
// Task worker
// Connects PULL socket to tcp://localhost:5557
// Collects workloads from ventilator via that socket
// Connects PUSH socket to tcp://localhost:5558
// Sends results to sink via that socket
//
// Author: metadings
//
// Socket to receive messages on and
// Socket to send messages to
using (var context = new ZContext())
using (var receiver = new ZSocket(context, ZSocketType.PULL))
using (var sink = new ZSocket(context, ZSocketType.PUSH))
{
receiver.Connect(String.Format ("tcp://{0}:{1}",SenderIP,SenderPort));
sink.Connect(string.Format("tcp://{0}:{1}",sinkIP,sinkPort ));
Console.WriteLine("Worker " + workerid + " ready.");
// Process tasks forever
while (true)
{
var replyBytes = new byte[4];
receiver.ReceiveBytes(replyBytes, 0, replyBytes.Length);
int workload = BitConverter.ToInt32(replyBytes, 0);
Console.WriteLine("{0}.", workload); // Show progress
Thread.Sleep(workload); // Do the work
sink.Send(new byte[0], 0, 0); // Send results to sink
}
}
}
示例2: TaskWork
public static void TaskWork(string[] args)
{
//
// Task worker
// Connects PULL socket to tcp://127.0.0.1:5557
// Collects workloads from ventilator via that socket
// Connects PUSH socket to tcp://127.0.0.1:5558
// Sends results to sink via that socket
//
// Author: metadings
//
// Socket to receive messages on and
// Socket to send messages to
using (var context = new ZContext())
using (var receiver = new ZSocket(context, ZSocketType.PULL))
using (var sink = new ZSocket(context, ZSocketType.PUSH))
{
receiver.Connect("tcp://127.0.0.1:5557");
sink.Connect("tcp://127.0.0.1:5558");
// Process tasks forever
while (true)
{
var replyBytes = new byte[4];
receiver.ReceiveBytes(replyBytes, 0, replyBytes.Length);
int workload = BitConverter.ToInt32(replyBytes, 0);
Console.WriteLine("{0}.", workload); // Show progress
Thread.Sleep(workload); // Do the work
sink.Send(new byte[0], 0, 0); // Send results to sink
}
}
}
示例3: Espresso_Subscriber
static void Espresso_Subscriber(ZContext context)
{
// The subscriber thread requests messages starting with
// A and B, then reads and counts incoming messages.
using (var subscriber = new ZSocket(context, ZSocketType.SUB))
{
subscriber.Connect("tcp://127.0.0.1:6001");
subscriber.Subscribe("A");
subscriber.Subscribe("B");
ZError error;
int count = 0;
while (count < 5)
{
var bytes = new byte[10];
int bytesLength;
if (-1 == (bytesLength = subscriber.ReceiveBytes(bytes, 0, bytes.Length, ZSocketFlags.None, out error)))
{
if (error == ZError.ETERM)
return; // Interrupted
throw new ZException(error);
}
++count;
}
Console.WriteLine("I: subscriber counted {0}", count);
}
}