关键字: 扩展配置, 自定义配置, 自定义属性, 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="Policy\flash.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;

}

}

supersockets扩展服务器配置的更多相关文章

  1. about Red_Hat_Enterprise_Linux_7

    systemd systemd 是 Linux 的系统和服务管理程序,替换了 Red Hat Enterprise Linux 之前的发行本中使用的 SysV.systemd 与 SysV 和 Lin ...

  2. supersockets服务器配置热更新

    Keywords: 配置,热更新 此功能能够允许你在不重启服务器的前提下更新服务器实例的配置. (仅限1.6.5及其以上版本)

  3. PHP-Redis扩展使用手册(一)

    //初始化redis实例 $redis = new Redis(); /* connect . open 链接redis * @param string host redis服务器地址 * @para ...

  4. Dynamics AX 2012 R2 安装Reporting Services 扩展

    今天Reinhard在VS中部署SSRS报表时,接到以下错误: 部署因错误而被取消.在报表服务器上,验证:-SQL Server Reporting Services 服务是否正在运行. 接着,Rei ...

  5. Centos安装Memcached和(Nginx)Memcache扩展详细教程

    下载memadmin,下载地址:http://www.junopen.com/memadmin/ 并在IIS新建站点. 测试地址:http://wap.yousawang.com/mem , 1.重启 ...

  6. 【T电商 3】Nginx的Http(图片)服务器配置+ftp上传使用说明

    在前两篇博客中提到了搭建Nginx和Ftp服务器,在本篇博客,主要是介绍Nginx的配置文件的使用,怎样修改配置文件使其成为一个图片服务器. 一.Nginx图片服务器配置 <span style ...

  7. Win2003_IIS+PHP+MYSQL 全能服务器配置

    WIN2003_IIS+PHP+mysql最新版_全能服务器配置 本次配置PHP的服务器环境:Windows2003+IIS6+ASP+PHP5+MySQL5整个配置过程需要是使用拥有管理员权限的系统 ...

  8. ssh2 php扩展

    如何通过PHP启动和关闭远程服务器上的某个软件,譬如Memcached.对于俺这个刚刚掌握PHP编程皮毛的菜鸟来说,最直接不过的想法就是用exec函数执行SSH命令呗,先把运行Apache+PHP的服 ...

  9. SmartWiki开发日记之Laravel缓存扩展

    SmartWiki简介请阅读: http://www.cnblogs.com/lifeil/p/6113323.html 因为SmartWiki的演示站点部署在阿里云上,阿里云有一个128M免费的Me ...

随机推荐

  1. Leetcode637.Average of Levels in Binary Tree二叉树的层平均值

    给定一个非空二叉树, 返回一个由每层节点平均值组成的数组. class Solution { public: vector<double> averageOfLevels(TreeNode ...

  2. oracle 控制结构

    1.if 逻辑结构 if/then 结构是最简单的条件测试,如果条件为真,则执行程序的一行或者多行,如果条件为假,则什么都不执行, 示例: if  1>2 then null; end if ; ...

  3. 【每日一linux命令7】用户及用户组

    一.查询用户及用户组相关命令 1.whoami 查询当前登录的用户名 2.groups 查询当前登录用户名所在的用户组 3.groups root 查询root用户名所在的用户组 二.怎么批量查看用户 ...

  4. bzoj 1191 [HNOI2006]超级英雄Hero——二分图匹配

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1191 不就是个最大匹配么. 结果WA得不行. 看TJ后发现题面上说了一旦没回答出一道题就结束 ...

  5. 基于keras中IMDB的文本分类 demo

      本次demo主题是使用keras对IMDB影评进行文本分类: import tensorflow as tf from tensorflow import keras import numpy a ...

  6. react-native-login-redux

    项目地址如下 https://github.com/agunbuhori/react-native-login-redux 先看页面 ```js // 还有中英文切换 //src/global.js ...

  7. Codeforces 414A

    题目链接 首先考虑无解的情况: n / 2 > k 或者 n==1 且 k != 0 (因为两个数的最大公约数最小为1) 然后因为有 n / 2 组(把 a[i] 和 a[i+1] 看成一组), ...

  8. (转) Hibernate持久化类与主键生成策略

    http://blog.csdn.net/yerenyuan_pku/article/details/65462930 Hibernate持久化类 什么是持久化类呢?在Hibernate中持久化类的英 ...

  9. Linux与Unix shell编程指南(完整高清版).pdf

    找到一本很详细的Linux Shell脚本教程,其实里面不光讲了Shell脚本编程,还介绍了系统的各种命令 http://vdisk.weibo.com/s/yVBlEojGMQMpv 本书共分五部分 ...

  10. Directx11教程(64) tessellation学习(6)-PN Triangles

    原文:Directx11教程(64) tessellation学习(6)-PN Triangles       前面我们用tessellation细分三角形或者四边形,产生的细分点都是在三角形或四边形 ...