我有一个客户端应用程序,它使用Dealer套接字类型发送消息,我正在使用官方页面中的示例(http://zguide.zeromq.org/cs:asyncsrv)
public static void ClientTask()
{
using (var context = ZmqContext.Create())
{
using (ZmqSocket client = context.CreateSocket(SocketType.DEALER))
{
// Generate printable identity for the client
string identity = ZHelpers.SetID(client, Encoding.Unicode);
client.Connect("tcp://localhost:5570");
client.ReceiveReady += (s, e) =>
{
var zmsg = new ZMessage(e.Socket);
Console.WriteLine("{0} : {1}", identity, zmsg.BodyToString());
};
int requestNumber = 0;
var poller = new Poller(new List<ZmqSocket> { client });
while (true)
{
// Tick once per second, pulling in arriving messages
for (int centitick = 0; centitick < 100; centitick++)
{
poller.Poll(TimeSpan.FromMilliseconds(10));
}
var zmsg = new ZMessage("");
zmsg.StringToBody(String.Format("request: {0}", ++requestNumber));
zmsg.Send(client);
}
}
}
}
我的问题是如何从这些用途之外发送消息?我想只连接一次到服务器并保持连接打开,直到我发送注销到服务器,但不知何故我无法弄明白。
有这样的已知模式吗?