Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

I am wondering whether an out-of-process COM server has a chance to find out whether its clients are alive or dead, and to properly terminate the connection to any clients that have died. I am using MS VC++ with MFC and ATL. Any ideas?

Thanks, Hans
Posted
Comments
Eugen Podsypalnikov 13-Jul-11 5:57am    
What is a "connection" in your case,
why does it need any maintenance ? :)
hans.sch 13-Jul-11 6:21am    
A "connection" is established by a call to CoCreateInstanceEx(). When I close down the connection (this happens when I assign 0 to the CComPtr - calls Release() behind the scenes) the server knows one client has said goodbye, and when the last client is gone, the server process terminates. Unfortunately this doesn't happen when the client crashes.
Eugen Podsypalnikov 13-Jul-11 6:35am    
0. A "life" message from a client with its ID - once per one minute
and a "death" timeout for two - as a communication low ? :)

1. Try to hold the client's communication object as global static object
with the CreateInstance(..) in its constructor ant Release(..) in its destructor :)

As far as I am aware the only way to have any communication with the client, is if the client provides a callback link to the server. However, even then it would be difficult to determine the state of the client without some predefined protocol.
 
Share this answer
 
Comments
hans.sch 13-Jul-11 9:02am    
This is quite a good idea. I am using connection points, so I can call IDispatch::GetIDsOfNames. When the function returns something that is neither S_OK nor DISP_E_UNKNOWNNAME, I assume the client is dead, and I call my cleanup code. But how do I clean up the server-side COM object? I tried calling Release() but it didn't delete the object because the refcount was still 4, and I tried to delete it (using the 'delete' operator) but then I get an access violation when WinMain calls CoUninitialize before it exits.
This is more general than C++/COM question.
In OPC server-client communication (as in many kinds of communications) which is a kind of COM server-client connection you create a variable on server which is periodically (often as you can suppose) updated by the client. This is sometimes called "keep alive" signal or similar.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900