Jeremy
Jeremy

Reputation: 46410

How to test a remoting connection (check state)

I have an object created in a host application and can access it remotely using remoting, is there any way I can test the connection to ensure it is still "alive"? Maybe an event I can use that fires if the remoting connection gets disconnected, or some property that can tell me the state of the remoting connection. Is there something like this available?

Upvotes: 5

Views: 5887

Answers (2)

Sunny Milenov
Sunny Milenov

Reputation: 22310

What benefit will you have to check the connection? Even if you ping it, it does not mean that in the next moment the connection will still be alive when you make your remoting call.

Just try/catch you remoting calls and you will know.

This type of checks are meaningless (net connection, file locking, etc.). As the state of the thing you check can change immediately after the check. You just tray, and cleanup/retry if it fails.

Upvotes: 6

Charles Bretana
Charles Bretana

Reputation: 146559

I generally add another method to the remoting server MarshallByRef class, (I generally name it Ping(), as in:

 public void Ping() {} 

that does nothing, and returns nothing.. Then to "test" my connection, I call this method... If it throws a System.Net.Sockets.Exception, I have lost the connection....

Upvotes: 9

Related Questions