Skip to content

Instantly share code, notes, and snippets.

@lzbgt
Last active December 20, 2021 13:33
Show Gist options
  • Save lzbgt/7c56aa369af3cd7bd2a8931e26a15c07 to your computer and use it in GitHub Desktop.
Save lzbgt/7c56aa369af3cd7bd2a8931e26a15c07 to your computer and use it in GitHub Desktop.
csharp netmq zmq client demo
using System;
using System.Text;
using NetMQ;
using NetMQ.Sockets;
using System.Threading;
namespace cshap_zmq
{
class Program
{
static DealerSocket client;
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
client = new DealerSocket();
client.Options.Identity =
Encoding.Unicode.GetBytes("csharp_client");
client.Connect("tcp://127.0.0.1:2123");
client.SendFrame("hello");
var th = new Thread(heartbeat);
th.Start();
while (true)
{
var msgs = client.ReceiveMultipartMessage();
for (int i = 0; i < msgs.FrameCount; i++)
{
Console.WriteLine(msgs[i].ConvertToString(Encoding.UTF8));
}
}
}
private static void heartbeat(object obj)
{
var msg = new NetMQMessage();
while (true)
{
client.SendFrame("heartbeat");
Thread.Sleep(2000);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment