• 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: }
    作者:江振宇
    出处:http://jzywh.cnblogs.com
    本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。
  • 相关阅读:
    局域网中CSMA/CD协议的应用
    RIP及距离向量算法
    网桥与以太网交换机
    C++ String
    C++ Input & Output
    Shell Script(1)----variable compare
    python--内建函数(1)
    python--data type
    python--compile
    python--help
  • 原文地址:https://www.cnblogs.com/jzywh/p/2036919.html
Copyright © 2020-2023  润新知