views:

24

answers:

1

I'm working on an app that uses .net remoting for IPC.

When my client app starts up, it uses the following code to connect to the server:

  chnl = gcnew HttpChannel();
  ChannelServices::RegisterChannel(chnl, false);      
  IPCObjectInstance = (BaseRemoteObject)Activator.GetObject(
     typeof(BaseRemoteObject),
     "http://localhost:1237/MyRemoteObject.soap");

And, when I make my function call, I use the following code:

  BaseRemoteObject.GetFileTextDelegate svd = new BaseRemoteObject.GetFileTextDelegate(IPCObjectInstance, BaseRemoteObject.GetFileText);
  AsyncCallback  callback  = new AsyncCallback(this, &ClientGUI.RecievedStringText);
  IAsyncResult  arValSet  = svd.BeginInvoke(callback, null);

This code works great as is. However, I want my client to detect whether or not the server is running when it boots, and display the appropriate error message.

When the server isn't running, the client waits for about 3 seconds, before throwing a web exception (shown at bottom). There is no error "location", so I'm not sure of where to put the try\catch block.

What is the best way to detect my server not running?

Thanks!

+1  A: 

It should work to do a try/catch around your BeginInvoke line.

But my suggestion would be to create a Status method which you call synchrously instead of async, and do try/catch around that call instead. It can be a dummy method doing nothing.

It also possible to open a tcp connection to the remote server on the port specified and see if you get a connection. But this would be much like try/catch around a remoting call.

Mikael Svenson
The DoNothing function called synchroniously worked great, thanks!
greggorob64