本文整理汇总了C#中ZmqSocket类的典型用法代码示例。如果您正苦于以下问题:C# ZmqSocket类的具体用法?C# ZmqSocket怎么用?C# ZmqSocket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ZmqSocket类属于命名空间,在下文中一共展示了ZmqSocket类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendMessage
public static void SendMessage(byte[] address, byte[] message, ZmqSocket socket)
{
ZmqMessage zmqMessage = new ZmqMessage();
zmqMessage.Append(new Frame(address));
zmqMessage.Append(new Frame(message));
socket.SendMessage(zmqMessage);
}
示例2: SendRequest
public static void SendRequest(Int32 request,ref ZmqSocket socket)
{
//ZmqSocket socket;
try
{
//socket = CreateSocket();
var message = new ZmqMessage();
message.Append(Encoding.UTF8.GetBytes(String.Format(" Hello {0}.", request)));
socket.SendMessage(message);
// TODO: add receive timeout as param
var dataResult = socket.ReceiveMessage();
Console.WriteLine(Encoding.UTF8.GetString(dataResult[0]));
Console.WriteLine(Encoding.UTF8.GetString(dataResult[1]));
}
catch (Exception ex)
{
socket.Close();
socket = CreateSocket();
Console.WriteLine(ex.ToString());
}
}
示例3: Service1
public Service1(ZmqSocket socket)
{
_timer.Interval = 3000;
_socket = socket;
InitializeComponent();
}
示例4: RecieverPollInHandler
private void RecieverPollInHandler(ZmqSocket reciever, ZmqSocket sender)
{
Thread.Sleep(100);
var fileToMeasure = reciever.Receive(Encoding.Unicode);
Int64 fileLength = 0;
FileStream fs = null;
try
{
fs = File.OpenRead(fileToMeasure);
fileLength = fs.Length;
}
catch (IOException)
{
}
finally
{
if (fs != null) fs.Dispose();
}
Console.Write(".");
sender.Send(fileLength.ToString(), Encoding.Unicode);
}
示例5: Receive
public static KvMsg Receive(ZmqSocket subscriber)
{
var key = subscriber.Receive(Encoding.Unicode);
var sequence = BitConverter.ToInt64(Encoding.Unicode.GetBytes(subscriber.Receive(Encoding.Unicode)), 0);
var body = subscriber.Receive(Encoding.Unicode);
return new KvMsg(sequence, key, body);
}
示例6: Send
public void Send(ZmqSocket socket)
{
for (int index = frames.Count - 1; index > 0; index--)
{
socket.SendMore(frames[index]);
}
socket.Send(frames[0]);
}
示例7: Receive
public void Receive(ZmqSocket ZmqSocket)
{
var zmqMessage = ZmqSocket.ReceiveMessage();
foreach (var frame in zmqMessage)
{
frames.Insert(0, frame.Buffer);
}
}
示例8: SocketEventArgs
internal SocketEventArgs(ZmqSocket socket, PollEvents readyEvents)
{
if (socket == null)
{
throw new ArgumentNullException("socket");
}
this.Socket = socket;
this.ReceiveReady = readyEvents.HasFlag(PollEvents.PollIn);
this.SendReady = readyEvents.HasFlag(PollEvents.PollOut);
}
示例9: Bind
public override void Bind(ZmqSocket socket, ZeroRoute config)
{
ZeroLog.LogInfo("push bind....");
foreach (var endPoint in config.ConnectEndPoints())
{
socket.Connect(endPoint);
ZeroLog.LogInfo("push bind....");
}
}
示例10: ZmqMessageSender
internal ZmqMessageSender(Uri serviceUri)
{
context = ZmqContext.Create();
socket = context.CreateSocket(SocketType.REQ);
var address = string.Format("tcp://{0}:{1}", serviceUri.Host, serviceUri.Port);
socket.Connect(address);
}
示例11: ClientForm
public ClientForm()
{
InitializeComponent();
context = ZmqContext.Create();
client = context.CreateSocket(SocketType.REQ);
client.Connect("tcp://localhost:5555");
}
示例12: ZmqPublisher
public ZmqPublisher(string endpoint)
{
_endpoint = endpoint;
_context = ZmqContext.Create();
_socket = _context.CreateSocket(SocketType.PUB);
_socket.Bind(_endpoint);
}
示例13: InitialiseSocket
public void InitialiseSocket()
{
m_PublishSocket = m_Context.CreateSocket(SocketType.PUB);
m_PublishSocket.Bind("epgm://239.1.1.1:9500");
m_PublishSocket.Bind("tcp://*:9500");
m_PublishSocket.Bind("inproc://Local");
}
示例14: Subscriber
public Subscriber(string _guid, string _targetGuid, string _host, int _port, ZmqContext _ctx)
{
guid = _guid;
targetGuid = _targetGuid;
host = _host;
port = _port;
if (port > 0)
connectionString = String.Format("tcp://{0}:{1}", host, port);
else
connectionString = String.Format("inproc://{0}", targetGuid.ToLower());
buf = new byte[1024 * 1024];
subscribeChannels = new List<string>();
if (_ctx == null)
{
shardedCtx = false;
ctx = ZmqContext.Create();
}
else
{
shardedCtx = true;
ctx = _ctx;
}
socket = ctx.CreateSocket(SocketType.SUB);
if (log.IsDebugEnabled) log.DebugFormat("Subscriber connecting to: `{0}`", connectionString);
socket.Subscribe(Proxy.StringToByteArray(guid));
socket.Connect(connectionString);
socket.ReceiveHighWatermark = 1000000;
socket.ReceiveBufferSize = 128 * 1024;
lastActiveTime = Proxy.Unixtimestamp();
log.InfoFormat("Connected successfuly to: `{0}` `{1}`", connectionString, targetGuid);
}
示例15: Open
private static void Open(Object cancelationToken)
{
context = ZmqContext.Create();
frontend = context.CreateSocket(SocketType.ROUTER);
backend = context.CreateSocket(SocketType.DEALER);
backend.Identity = Encoding.UTF8.GetBytes("inproc://workers");
frontend.Bind("tcp://127.0.0.1:5000");
backend.Bind("inproc://workers");
workerThreads = new Thread[2];
for (int threadId = 0; threadId < workerThreads.Length; threadId++)
{
workerThreads[threadId] = new Thread(WorkerRoutine);
workerThreads[threadId].Start(context);
}
frontend.ReceiveReady += new EventHandler<SocketEventArgs>(frontend_ReceiveReady);
backend.ReceiveReady += new EventHandler<SocketEventArgs>(backend_ReceiveReady);
Poller poller = new Poller(new[] { frontend, backend });
var token = (CancellationToken)cancelationToken;
while (!token.IsCancellationRequested)
{
poller.Poll(TimeSpan.FromMilliseconds(100));
}
}