How to test a remote connection (check status)

I have an object created in the host application, and you can access it remotely using remote access, is there any way to check the connection so that it is alive? Perhaps the event that I can use is triggered if the remote connection is disconnected, or some property that can tell me about the status of the remote connection. Is there something similar?

+4
source share
2 answers

Usually I add another method for the MarshallByRef class of the remote node, (I generally call it Ping (), as in:

public void Ping() {} 

which does nothing and returns nothing. Then, to "check" my connection, I call this method ... If it calls System.Net.Sockets.Exception, I lost the connection ....

+8
source

What benefits will you need to check? Even if you ping this, it does not mean that in the next moment the connection will remain alive when you make your remote call.

Just try / catch the remote calls and find out.

This type of check does not make sense (network connection, file locking, etc.). Since the state of the thing you are checking can change immediately after checking. You just tray, and clean / redo if it doesn't work.

+5
source

All Articles