关键字: 扩展配置, 自定义配置, 自定义属性, 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. PHP把图片保存到数据库,将图片本身保存在数据库,而非保存路径

    备注 百度开发者的云代码空间为了保证高可用,不允许用户将图片保存到代码空间中,使用CDN或者对象存储不仅收费而且使用比较复杂,于是考虑能否将img存储在数据库中,虽然很多人说会造成性能问题,权当一试 ...

  2. windows下maven的安装配置

    什么是maven Maven是基于POM(工程对象模型),通过一小段描述来对项目的代码.报告.文件进管理的工具. Maven是一个跨平台的项目管理工具,它是使用java开发的,它要依赖于jdk1.6及 ...

  3. 【python之路14】发送邮件实例

    1.发邮件的代码 from email.mime.text import MIMEText from email.utils import formataddr import smtplib msg ...

  4. QT_强杀进程

    #ifdef WIN32 bool res = false; HANDLE hToolHelp32Snapshot; hToolHelp32Snapshot = CreateToolhelp32Sna ...

  5. iOS 使用Quartz和OpenGL绘图

    http://blog.csdn.net/coder9999/article/details/7641701 第十二章 使用Quartz和OpenGL绘图 有时应用程序需要能够自定义绘图.一个库是Qu ...

  6. js的动态tab导航

    html部分 <div class="container"> <h3 class="page-header">tab切换</h3& ...

  7. UWP获取任意网页加载完成后的HTML

    主要思想:通过后台WebView载入指定网页,再提取出WebView中的内容 关键代码: var html = await webView.InvokeScriptAsync("eval&q ...

  8. JavaScript--函数中this的几种指向

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. (转)jQuery中append(),prepend()与after(),before()的区别

    在jQuery中,添加元素有append(),prepend和 after(),before()两种共四个. 根据字面意思我们可以看出他们分别是追加,添加和之前,之后,意思相近.同时他们又都有添加元素 ...

  10. KDD2015,Accepted Papers

    Accepted Papers by Session Research Session RT01: Social and Graphs 1Tuesday 10:20 am–12:00 pm | Lev ...