unexpected behavior of push/pull sockets in netmq (zeromq) -


i trying use netmq (the port of zeromq). here problem found. here code:

class program {     private static netmqcontext context;      static void main(string[] args)     {         context = netmqcontext.create();         using (var puller = context.createpullsocket())         {             puller.bind("tcp://127.0.0.1:5651");             thread.sleep(500);             (int = 0; < 5; i++)             {                 task.run(new action(pushethread));             }             console.writeline("any key start receive");             console.readkey();             msg msg = new msg();             msg.initempty();             (; puller.tryreceive(ref msg, new timespan(0, 0, 5)); msg = new msg(), msg.initempty())             {                 var s = encoding.utf8.getstring(msg.data);                 console.writeline(s);             }         }         console.writeline("any");         console.readkey();     }      static void pushethread()     {         var guid = guid.newguid();         console.writeline("started: " + guid);         using (var pusher = context.createpushsocket())         {             pusher.connect("tcp://127.0.0.1:5651");             (int = 0; < 5; i++)             {                 pusher.send("helo! " + guid);             }         }     } } 

if run code , watch in console saw messages lost. like:

any key start receive started: 8aeca8e5-ed41-4055-ab72-750a0e61a680 started: 4211d77a-ad9f-40f1-9382-121156325128 started: bd735e75-2692-4abe-b8b1-fbddbe21e546 started: 6749d3bb-6b2b-4caa-b22e-755dba4d932d started: 281ff59e-4430-4fc6-9435-4dc2c5e6015e helo! 8aeca8e5-ed41-4055-ab72-750a0e61a680 helo! 6749d3bb-6b2b-4caa-b22e-755dba4d932d helo! 8aeca8e5-ed41-4055-ab72-750a0e61a680 helo! 6749d3bb-6b2b-4caa-b22e-755dba4d932d helo! 8aeca8e5-ed41-4055-ab72-750a0e61a680 helo! 6749d3bb-6b2b-4caa-b22e-755dba4d932d helo! 8aeca8e5-ed41-4055-ab72-750a0e61a680 helo! 6749d3bb-6b2b-4caa-b22e-755dba4d932d helo! 8aeca8e5-ed41-4055-ab72-750a0e61a680 helo! 6749d3bb-6b2b-4caa-b22e-755dba4d932d 

as see no messages 4211d77a-ad9f-40f1-9382-121156325128, bd735e75-2692-4abe-b8b1-fbddbe21e546 , another. problem in multithreading? or doing wrong? thanks.

the problem in pushethread simple kill of newly created pushsocket fast.

static void pushethread() {     var guid = guid.newguid();     console.writeline("started: " + guid);     using (var pusher = context.createpushsocket())     {         pusher.connect("tcp://127.0.0.1:5651");         (int = 0; < 5; i++)         {             pusher.send("helo! " + guid);         }         thread.sleep(5000);     } } 

even though isn't solid solution, should prove problem pushsocket disposed using statement before being able send messages.

that messages through shows how fast netmq , zeromq :)


Comments