How can I test if the server is down, in Remoting?
I used remoting to set up servers and clients. The servers marshal an object, and the clients connect to this object and pass data and delegates to and fro.
I could not see any mechanism for checking programatically if the server is down. Oh, certanly, there is the exception try-catch trick. Somehow it seems to me that there must be other ways to do that.
More exactly, here is what I do (nothing suprising, just like in the documentation):
- the server sets up a channel:
---
IDictionary hTab = new Hashtable();
hTab["name"] = "YetAnotherTCPChannel";
hTab["port"] = portNr; // an integer set before
TcpServerChannel channel = new TcpServerChannel(hTab,
new BinaryServerFormatterSinkProvider());
ChannelServices.RegisterChannel(channel);
---
- the server marshals an object:
---
ObjRef o = RemotingServices.Marshal(
this.localObject, "EndPoint", typeof(ClassOfMarshalledObject))
---
- the client registers the client type:
---
RemotingConfiguration.RegisterWellKnownClientType(
typeof(ClassOfLocalObject),
"tcp://localhost:"+portNr.ToString()+"EndPoint");
---
- the client creates a proxy:
---
remoteObj = new ClassOfMarshalledObject();
---
Later, the client calls methods of the remote object:
---
try{
remoteObj.methodCall(localData);
}
catch (Exception e){
// probably the server is down
}
---
I would like to have a mechanism for testing whether the channel has closed/disconnected, or whether the remote object is still there.
Petru
testing remote connection
I have already mentioned the try-catch mechanism in the first message of the thread - this is what I am currently using, but I am not satisfied.
The main reason is that the client actually tries to interrogate the server, for a few seconds, before giving up and raising an error. There may be various reasons for that exception, like, e.g., the TCP channel has broken, the server is down, or even the leasing time of the marshalled object has expired. Or the server has never been up, or the remote object has never been marshalled.
Now certainly one can check the exception raised (although the error code/message is not always evident) and use the code intelligently, in the program; I am trying to find out whether there are _other_ ways of checking the connection _before_ raising an exception. I could not find anything from just studying the RemotingServices, ChannelServices, TcpChannel, etc. Most probably there are none...
The server and the client are always on the same computer (related to the first message of Pareshgh).
Thanks,
Petru