文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>SuperSocket系列文档(11) 扩展服务器配置

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

时间:2011-05-04  来源:江大鱼

实现自己的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: }
排行榜 更多 +
地狱摩托游戏最新版下载

地狱摩托游戏最新版下载

赛车竞速 下载
小猫快来钓鱼游戏下载

小猫快来钓鱼游戏下载

休闲益智 下载
殴打氪金大佬昊天手游下载

殴打氪金大佬昊天手游下载

休闲益智 下载