netmq
netmq copied to clipboard
How to know if connection was successful and is alive?
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
You can always implement a simple "heart-beat" pattern to check if endpoint alive. This pattern is fully described in Zero-Mq docs
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.
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;