-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
I implemented NetMQ Security following the example in the test folder and it worked perfectly even with the poller.
When I added Queue (I'd like to use multithreads) the request is sent but there is no reply. The message doesn't even get to the Server and there is no error.
If I comment out lines
req.Options.CurveServerKey = serverPair.PublicKey;
req.Options.CurveCertificate = clientPair;and
rep.Options.CurveServer = true;
rep.Options.CurveCertificate = serverPair;program works as it should. What could be the problem?
Program that halts:
namespace ZeroMqQueue
{
public class Class1
{
private static CancellationToken s_token;
private static QueueDevice queue;
private static CancellationTokenSource source;
private static NetMQCertificate serverPair = new NetMQCertificate("..string...", "...string...");
private static NetMQCertificate clientPair = new NetMQCertificate("..string...", "...string...");
public static void Main()
{
queue = new QueueDevice("tcp://localhost:5000", "tcp://localhost:5001", DeviceMode.Threaded);
source = new CancellationTokenSource();
s_token = source.Token;
for (int threadId = 0; threadId < 2; threadId++)
Task.Factory.StartNew(WorkerRoutine, s_token);
queue.Start();
var clientThreads = new List<Task>();
for (int threadId = 0; threadId < 8; threadId++)
{
int id = threadId;
clientThreads.Add(Task.Factory.StartNew(() => ClientRoutine(id)));
}
Task.WaitAll(clientThreads.ToArray());
}
private static async Task ClientRoutine(object clientId)
{
using (var req = new RequestSocket())
{
req.Connect("tcp://localhost:5000");
req.Options.CurveServerKey = serverPair.PublicKey;
req.Options.CurveCertificate = clientPair;
Console.WriteLine("sending");
req.SendFrame("Message");
Console.WriteLine(req.ReceiveFrameString());
}
}
private static void WorkerRoutine()
{
using (var rep = new ResponseSocket())
using (var poller = new NetMQPoller { rep })
{
rep.Connect("tcp://localhost:5001");
rep.Options.CurveServer = true;
rep.Options.CurveCertificate = serverPair;
rep.ReceiveReady += RepOnReceiveReady;
poller.Run();
}
}
private static void RepOnReceiveReady(object sender, NetMQSocketEventArgs args)
{
NetMQSocket rep = args.Socket;
Console.WriteLine("Rec");
rep.ReceiveFrameString();
rep.TrySendFrame("Recieved");
}
}
}Metadata
Metadata
Assignees
Labels
No labels