[zeromq-dev] [NetMQ] How to properly free a monitor in order to be able to recreate one?

Doron Somech somdoron at gmail.com
Mon Mar 23 21:14:27 CET 2015


It is a bug. Anyway you can work around it by calling server.Monitor with
null as the endpoint before closing the server.


On Mon, Mar 23, 2015 at 6:48 PM, Leonard Michelet <
leonard.michelet at openwide.fr> wrote:

> Hello everyone, I'm having problem using Monitor with NetMQ. Please tell
> me if there is a dedicated place to ask about NetMQ, or possibly report bug.
> Here's what I do :
>  1) I create and bind a DEALER socket, associate a monitor to it and start
> monitoring it.
>  2) Then I Unbind the socket, stop monitoring, dispose everything but the
> NetMQContext.
>  3) Finally, I want to start again 1) but I receive a NetMQException
> because the inproc socket created by the DEALER socket to send event to its
> monitor is still alive.
>
> Next is a simple code to see my problem :
>
> using System;
> using System.Threading;
> using NetMQ;
> using System.Threading.Tasks;
> using NetMQ.Monitoring;
> using NetMQ.zmq;
>
> namespace Server
> {
>     class ServerProg
>     {
>         static void CreateServerSocket(NetMQContext ctx)
>         {
>             try
>             {
>                 using (var server = ctx.CreateDealerSocket())
>                 {
>                     var monitor = new NetMQMonitor(ctx, server,
> "inproc://*:4556.monitor",
>                                                    SocketEvent.Connected |
> SocketEvent.Disconnected);
>                     Task monitorTask =
> Task.Factory.StartNew(monitor.Start);
>                     server.Bind("tcp://*:4556");
>                     Thread.Sleep(500);
>                     server.Unbind("tcp://*:4556");
>                     monitor.Stop();
>                     monitor.Dispose();
>                     server.Close();
>                     server.Dispose();
>                 }
>             }
>             catch (NetMQException e)
>             {
>                 Console.Out.WriteLine("Exception: " + e);
>                 throw;
>             }
>         }
>
>         static void Main(string[] args)
>         {
>             using (NetMQContext ctx = NetMQContext.Create())
>             {
>                 CreateServerSocket(ctx);
>                 CreateServerSocket(ctx);
>             }
>         }
>     }
> }
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20150323/30bac191/attachment.htm>


More information about the zeromq-dev mailing list