透明代理指向哪里?

发布于 2024-08-15 16:29:16 字数 1297 浏览 1 评论 0原文

我正在使用 .Net 远程处理。我有一个服务公开一个单例类,另一台机器上的客户端可以向该类注册,以便服务器可以向所有注册的客户端广播消息。

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

现在,在我的服务中,在发布这些消息的方法中,我想阻止代码多次向同一客户端发送相同的消息。因此,我正在迭代服务器的委托。

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
       }
    }
    // ..... 

现在,每个委托 mAH 都包含一个方法(在调用委托时将调用该方法)。它还包含一个 Target 属性,该属性(例如方法)填充了对将调用此方法的对象。

但对于像这样的远程事件,委托已通过 .Net Remoting 通道由远程客户端的事件注册填充。因此,在本例中,此目标属性由透明代理对象填充,而不是实际执行处理程序的远程客户端框中的对象。所以我的假设是,即使两个委托注册来自同一个远程对象上的相同方法,它们仍然会在服务器上获得不同的单独透明代理。现在我想做的是确保如果特定客户端以某种方式注册多次,服务器不会向该客户端多次传输相同的消息。 (...然后从调用列表中删除该额外的委托)。

所以我的问题是:如何通过查看委托或委托的目标属性中的透明代理来判断两个这样的委托实际上来自同一客户端计算机上的同一对象?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文