How to know when a CAO client has close?

I am using a CAO schema in a remoting scenario. I need to know when a client has close the app. It's a chat, and I need to know when clients close, so I report the session termination to the other clients. Any idea? Do u know about another schema wich could work better than CAO? I dont like singleton cause i cant have individual info for each client since they share the same object.

Thx in advance.

[405 byte] By [Jero] at [2008-2-12]
# 1

Use a Server Activated object implementing a factory pattern.
Your Server Activated has a method that returns the individual client objects, in this case they are instances of MyRemotedClass.

All code reflects the server side. . .

declare an event arg class such as:

public class ObjectDisconnectedArgs: EventArgs
{
public object DisconnectedObject;
public ClientDisconnectedArgs(object obj)
{
DisconnectedObject = obj;
}
}

declare a delegate:

public delegate void ObjectDisconnectedHandler(object sender, ObjectDisconnectedArgs e);
Implement ITrackingHandler in a class with a ObjectDisconnectedHandler event.
make your class something like:

public class ObjectTracker: ITrackingHandler
{
public event ObjectDisconnectedHandler ObjectDisconnected;

public void DisconnectedObject(object obj)
{
if (ObjectDisconnected == null) return;

MyRemotedClass ro = obj as MyRemotedClass;
if (ro != null)
ObjectDisconnected(this, new ObjectDisconnectedArgs(ro));
}

public void UnmarshaledObject(object obj, System.Runtime.Remoting.ObjRef or){}

public void MarshaledObject(object obj, System.Runtime.Remoting.ObjRef or){}
}

In your class factory, define a ObjectDisconnectedHandler method:

private void ObjectDisconnected(object sender. ObjectDisconnectedArgs e)
{
// do something with e.DisconnectedObject here
}

In InitializeLifeTimeServices of your class factory register your TrackingHandler class:

public override object InitializeLifetimeService()
{
ObjectTracker ot = new ObjectTracker();
ot.ObjectDisconnected += new ObjectDisconnectedHandler(ObjectDisconnected);
TrackingServices.RegisterTrackingHandler(ot);
return null;
}

make sense?
caveat emptor, may have typos but the gist is correct

BlairStark at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Remoting and Runtime Serialization...
# 2
Thanks for the answer. Nice work
Jero at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Remoting and Runtime Serialization...
# 3
you're welcome. . .

I highly recommend Ingo Rammer's:
Advanced .Net Remoting, second ed.
ISBN: 1-59059-417-7

The Microsoft? .NET Remoting blows chunks. . . avoid at all costs!!!

BlairStark at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Remoting and Runtime Serialization...

.NET Development

Site Classified