zoukankan      html  css  js  c++  java
  • supersockets扩展服务器配置

    关键字: 扩展配置, 自定义配置, 自定义属性, GetChildConfig, 读取配置,子节点

    当你使用 SuperSocket 实现 Socket 服务器的时候,不可避免的需要在配置文件中定义一些参数。 SuperSocket 提供了非常简单的方法,让你在配置文件中定义这些参数,然后在你的代码中读取它们。

    请看下面的配置代码:

    <server name="FlashPolicyServer"

            serverType="SuperSocket.Facility.PolicyServer.FlashPolicyServer, SuperSocket.Facility"

            ip="Any" port="843"

            receiveBufferSize="32"

            maxConnectionNumber="100"

            clearIdleSession="true"

            policyFile="Policyflash.xml">

    </server>

    在上面的配置中, 属性 "policyFile" 未在 SuperSocket 中定义, 不过你任然可以在你的 AppServer 类中读取它:

    public class YourAppServer : AppServer

    {

        private string m_PolicyFile;

        protected override bool Setup(IRootConfig rootConfig, IServerConfig config)

        { 

            m_PolicyFile = config.Options.GetValue("policyFile");

            if (string.IsNullOrEmpty(m_PolicyFile))

            {

                if(Logger.IsErrorEnabled)

                    Logger.Error("Configuration option policyFile is required!");

                return false;

            }

            return true;

        }

    }

    你不仅可以在 server 节点定义属性, 而且你还能像下面的代码那样定义子节点:

    <server name="SuperWebSocket"

            serverTypeName="SuperWebSocket"

            ip="Any" port="2011" mode="Tcp">

        <subProtocols>

            <!--Your configuration-->

        </subProtocols>

    </server>

    下面是所需的节点对应的配置类:

    /// <summary>

    /// SubProtocol configuration

    /// </summary>

    public class SubProtocolConfig : ConfigurationElement

    {

        //Configuration attributes

    }

    /// <summary>

    /// SubProtocol configuation collection

    /// </summary>

    [ConfigurationCollection(typeof(SubProtocolConfig))]

    public class SubProtocolConfigCollection : ConfigurationElementCollection

    {

        //Configuration attributes

    }

    然后你就能在 AppServer 类中读取这个子节点了:

    public class YourAppServer : AppServer

    {

        private SubProtocolConfigCollection m_SubProtocols;

        protected override bool Setup(IRootConfig rootConfig, IServerConfig config)

        { 

            m_SubProtocols = config.GetChildConfig<SubProtocolConfigCollection>("subProtocols");

            if (m_SubProtocols == null)

            {

                if(Logger.IsErrorEnabled)

                    Logger.Error("The child configuration node 'subProtocols' is required!");

                return false;

            }

            return true;

        }

    }

  • 相关阅读:
    鸟哥linux私房菜学习笔记,U盘安装centos5.3不能正常进入图形界面的问题
    loadrunner11的移动端性能测试之脚本录制
    JVM(java 虚拟机)内存设置
    数据结构一元多项式加减乘
    数据结构顺序表
    数据结构栈
    LoadIcon(nFaceID[i])
    数据结构单链表
    mysql得到wenshell
    窗口背景刷新的问题
  • 原文地址:https://www.cnblogs.com/fanweisheng/p/11126879.html
Copyright © 2011-2022 走看看