|
-
February 27th, 2003, 04:27 AM
#1
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
-
February 27th, 2003, 11:52 AM
#2
There are some suggestions here,
1) You can always check that port no localy on your machine. meaning that server and client runs on the same machine.
2) If the network machine is down then you can check before executing some statemetns. you can ping that machine if that machine returns with good value then its there in network and hence you can go from there.
3) You can implement some sort of stateless protocol sort of thing where in client and server doesn't have to depend upon anything. like : HTML and webpages or http protocol
-Paresh
-
March 1st, 2003, 03:51 AM
#3
try
{
...
...
...
catch(Exception ex)
{
...
...
...
}
That will catch any error, now you need to find out what the error is, to tell the client what did go wrong. (So to make it short, tell the client that the server is down)
WM.
What about weapons of mass construction?
-
March 1st, 2003, 06:34 AM
#4
or either you can use it without the exception also
like
try
{
}
catch
{
}
no need of object Exception ex, when not necessary
Paresh
-
March 3rd, 2003, 09:39 AM
#5
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
-
March 3rd, 2003, 04:29 PM
#6
if server /client are on the same machine then it shouldn't be a big problem. but ya you can always check a network machine before getting a TCP ... and if in btw it fails then u have to rely on try catch blocks... that's the standard practice.
checking the network machine will typically take time.
you can use ping also and ping to that machine. and get the result. execute shell command without console command and using process class with using processinfo. store the output in diff object and process it..
i am pretty sure that C# version of a ping is already available on the net.
u can search it.
but ping will also take 1-2 second to check machine if its not there on network. if its there then ping returns fast...you won't notice the difference.
Paresh
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|