netmq icon indicating copy to clipboard operation
netmq copied to clipboard

How to know if connection was successful and is alive?

Open maxima120 opened this issue 4 years ago • 3 comments

How do I know if connection is well and alive?

I connected to an non-existing IP by mistake and found that nothing happened in my code as if it was connected OK.. Only no messages came through :)

Environment

NetMQ 4.0.1.6:    
Operating System: Windows 10 x64
.NET Version:   .NET 5.0

Actual behaviour

SubscriberSocket .Connect(server) throws no errors if server doesnt exist

Expected behaviour

  • SubscriberSocket .Connect(server) should throw an error if server doesnt exist

  • an event handler/action has to be called called if disconnect or connection broken at any time

  • there has to be a method to check if connection is alive at any time

maxima120 avatar Dec 06 '20 13:12 maxima120

You can always implement a simple "heart-beat" pattern to check if endpoint alive. This pattern is fully described in Zero-Mq docs

b2yq avatar Feb 15 '21 06:02 b2yq

This issue has been automatically marked as stale because it has not had activity for 365 days. It will be closed if no further activity occurs within 56 days. Thank you for your contributions.

stale[bot] avatar Apr 17 '22 03:04 stale[bot]

Hi,

For detecting when a socket disconnects I use NetMQMonitor

subscriberSocket = new SubscriberSocket();
subscriberSocket.Connect(addr);

netMQPoller = new NetMQPoller
          {
              subscriberSocket
          };

netMQPoller.RunAsync();
NetMQMonitor monitor = new NetMQMonitor(subscriberSocket, $"inproc://addr:1234", SocketEvents.All);
monitor.Connected += _monitor_Connected;
monitor.Disconnected += _monitor_Disconected;

jramram avatar Jun 21 '22 11:06 jramram