SuperSocket 1.4系列文档(11) 扩展服务器配置

实现自己的Socket服务器,不免需要将某些参数放到配置文件之中。而SuperSocket提供了非常好用的接口让你将参数存入配置文件之中并且在你AppServer中能够方便的读取和使用。

如下配置代码:

   1: <server name="FlashPolicyServer"
   2:         serviceName="FlashPolicyService"
   3:         ip="Any" port="843"
   4:         mode="Async"
   5:         receiveBufferSize="32"
   6:         maxConnectionNumber="100"        
   7:         clearIdleSession="true"
   8:         policyFile="Policy\flash.xml">
   9: </server>

上面配置文件之中,server节点的最后一个属性policyFile="Policy\flash.xml"并非SuperSocket的内置配置属性,而是一个扩展属性。而这个扩展属性可以在你的AppServer类的重载Setup方法中读取,如下代码:

   1: public abstract class PolicyServer : AppServer<PolicySession, BinaryCommandInfo>
   2: {
   3:     private string m_PolicyFile;
   4:  
   5:     public PolicyServer()
   6:         : base()
   7:     {
   8:  
   9:     }
  10:  
  11:     public override bool Setup(IRootConfig rootConfig,
  12:                                IServerConfig config,
  13:                                ISocketServerFactory socketServerFactory,
  14:                                ICustomProtocol<BinaryCommandInfo> protocol)
  15:     {            
  16:         if (!base.Setup(rootConfig, config, socketServerFactory, protocol))
  17:             return false;
  18:  
  19:         m_PolicyFile = config.Options.GetValue("policyFile");
  20:  
  21:         if (string.IsNullOrEmpty(m_PolicyFile))
  22:         {
  23:             Logger.LogError("Configuration option policyFile is required!");
  24:             return false;
  25:         }
  26:  
  27:         return true;
  28:     }
  29: }
posted @ 2011-05-04 20:08  江大渔  阅读(2119)  评论(0编辑  收藏  举报