在远程对像类中设置一个静态变量,在构造函数中++,在析构函数中--.在客户端调用她的时候使用类名.静态变量判断她被实例化多少次。如果超过限制则不实例化,断开连接。Remoting好像使用的是同步长连接,好像无法设置超时。

解决方案 »

  1.   

    如果你使用的是http连接的话,在server声明channel的时候加入:
    IDictionary props = new Hashtable();
    props["port"] = 9000;
    props["clientConnectionLimit"] = 20;// default value is 2
    HttpChannel channel = new HttpChannel(
       props, 
       null, 
       new BinaryServerFormatterSinkProvider()
    );
    ChannelServices.RegisterChannel(channel);
      

  2.   

    remoting 仅仅使用static保存一计数器,是不够的。如果client非正常退出,计数器就没有办法释放。 turnmissile(会翻跟头的导弹) 方法建议还没用过,测试先楼主可参考:
    ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfsystemruntimeremotingchannelshttphttpchannelclasstopic.htm