views:

43

answers:

0

I am using .Net Remoting. I have a service exposing a singleton class that a client on another machine can register with, so that the server can broadcast messsages to all registered clients.

  MessageManager mgr = MessageManager.Instance; //Static Singleton Factory Proprty
  RemotingServices.Marshal(mgr, MesgURI);

Now in my service, in the method where I am publishing these messages, I want to stop the code from sending the same message to the same client more than once. So I am iterating through the server's delegate.InvocationList

public event MessageArrived SendMsgToClientEvent;
Delegate[] clientList = SendMsgToClientEvent.GetInvocationList();
List<int> dels = new List<int>();
foreach (Delegate d in clientList)
    try
    {
       mAH = (MessageArrived)d;
       int tgtHC = mAH.Target.GetHashCode();
       if (dels.Contains(tgtHC))        // If we already sent  
           SendMsgToClientEvent -= mAH; // to this one, delete it
       else 
       {
          mAH.BeginInvoke(msg, OnMsgCallComplete, null);
          dels.Add(tgtHC);    // keep track of which ones we've sent to
       }
    }
    // .....

Now each delegate mAH contains a method (which will be called when the delegate is invoked) It also contains a Target property, which, (for instance methods), is populated with a reference to the object that this method will be called against.

But for remote events like this, the delegate has been populated by event registrations from remote clients, over a .Net Remoting channel. So in this case, this target Property is populated with a Transparent Proxy object, not the object on the remote client box where the handler will actually be executed. So my assumption is that even if two delegate registrations come from the same method on the same remote object, they will each still get distinct individual transparent proxies on the server. Now what I want to do is ensure that if a specific client somehow registers more than once, that the server does not transmit the same message more than once to that client. (...and then remove that extra delegate from the invocation List).

So my question is: How can I tell, from looking at the delegate, or from the transparent proxy in the delegates' Target Property, that two such delegates are actually from the same object on the same client machine?