tags:

views:

40

answers:

2

I've got a COM solution with a client (an EXE) and a server (a service EXE). When the client is killed, or dies abnormally, I'd like to know about it in the server. Unfortunately, it appears that COM doesn't call Release when this happens.

How can I tell that a COM client has died, so that I can clean up for it?

Update: Answers so far require that the server have a pointer to the client, and call a method on it periodically (ping). I'd rather not do this, because:

  1. I don't currently have a callback pointer (server->client), and I'd prefer to avoid introducing one, unless I really have to.
  2. This still won't call Release on the object that represents the client endpoint, which means that I'll have to maintain the other client-specific resources separately, and hold a weak pointer from the "endpoint" to the other resources. I can't really call Release myself, in case COM decides to do it later.

Further to the second: Is there any way, in COM, to kill the client stub, in lieu of calling Release? Can I get hold of the stub manager for my object and interface and tell it to do cleanup?

A: 

Killing is rather extremal process, so neither CORBA, nor COM/DCOM nor Java's RMI has no explicit work around. Instead you can create very simple callback to implement 'ping'. It can be for example time based or on occasional base. Also you can think about third EXE - that works as monitor for your client and provides notification to server (a service).

Dewfy
A: 

Simplest solution is for the server to run a PING test on a timer.

In a multi threaded apartment setup this can run on a background thread.

This test should call from server to client with a call that's guaranteed to make it to the client if it is alive e.g. a QueryInterface call on a client object.

Unexpected failures can be treated as an indication that the client is dead.

The server will need to manage the list of clients it pings intelligently and should ensure that the ping logic itself doesn't keep the client alive.

morechilli