Remoting - Detect a crashed/disconnected client from the server?

J

JamesB

OK, after lots of faffing I have finally gotten remoting working - basically
I have a windows service (the "server") and a forms app (the "client").

The forms app can call methods in the server, and I can get events fired on
the server to be picked up and acted on in the client app, so all is well. I
can even get two client apps on different machines talking to the same
server instance and the events pop up on both.

This is all good until the "first" client app instance dies unexpectedly
(i.e. for testing, I am just killing it in task manager). The events never
reach the other instance, as the server seems to be sending out the events
synchronously to any connected clients. (I have got some code to unregister
the client/event in the form close event, so if you quit "gracefully" this
problem doesn't occur).

Is there any way of either a) removing a crashed client from the servers
internal list? (I do get an exception in the server when my event is fired,
basically saying the target machine actively refused connection - but what
to do with that info!) or b) can I send out my events from the server in
some async/simultaneous way so it doesn't matter if a client instance has
died or not.

I'd prefer option a as it seems neater, but hey-ho.

TIA

James.
 
N

Nicholas Paldino [.NET/C# MVP]

James,

When you get the reference to the client, you have an object that
derives from MarshalByRefObject. With that, you can call GetLifeTimeService
which will return an object. This object can be cast to an ILease instance
which you would then query to get the state of the connection back to the
client. If the state indicates that it is not connected (or an exception is
thrown), then you can try and unsubscribe through the ILease interface, and
proceed from there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top