Last active
December 20, 2021 13:33
-
-
Save lzbgt/7c56aa369af3cd7bd2a8931e26a15c07 to your computer and use it in GitHub Desktop.
csharp netmq zmq client demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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