À©Õ¹·þÎñÆ÷ÅäÖÃ
¹Ø¼ü×Ö: À©Õ¹ÅäÖÃ, ×Ô¶¨ÒåÅäÖ㬠×Ô¶¨ÒåÊôÐÔ, GetChildConfig, ¶ÁÈ¡ÅäÖã¬×ӽڵ㠵±ÄãʹÓà SuperSocket ʵÏÖ Socket ·þÎñÆ÷µÄʱºò£¬²»¿É±ÜÃâµÄÐèÒªÔÚÅäÖÃÎļþÖж¨ÒåһЩ²ÎÊý¡£ SuperSocket ÌṩÁ˷dz£¼òµ¥µÄ·½·¨£¬ÈÃÄãÔÚÅäÖÃÎļþÖж¨ÒåÕâЩ²ÎÊý£¬È»ºóÔÚÄãµÄ´úÂëÖжÁÈ¡ËüÃÇ¡£
Çë¿´ÏÂÃæµÄÅäÖôúÂ룺
serverType=\SuperSocket.Facility\ ip=\ receiveBufferSize=\ maxConnectionNumber=\ clearIdleSession=\ policyFile=\
ÔÚÉÏÃæµÄÅäÖÃÖУ¬ ÊôÐÔ \δÔÚ SuperSocket Öж¨Ò壬 ²»¹ýÄãÈÎÈ»¿ÉÒÔÔÚÄãµÄ AppServer ÀàÖжÁÈ¡Ëü£º
public class YourAppServer : AppServer {
private string m_PolicyFile;
protected override bool Setup(IRootConfig rootConfig, IServerConfig config) {
m_PolicyFile = config.Options.GetValue(\
if (string.IsNullOrEmpty(m_PolicyFile)) {
if(Logger.IsErrorEnabled)
Logger.Error(\ return false; }
return true; } }
Äã²»½ö¿ÉÒÔÔÚ server ½Úµã¶¨ÒåÊôÐÔ£¬ ¶øÇÒÄ㻹ÄÜÏñÏÂÃæµÄ´úÂëÄÇÑù¶¨Òå×ӽڵ㣺 serverTypeName=\ ip=\
ÏÂÃæÊÇËùÐèµÄ½Úµã¶ÔÓ¦µÄÅäÖÃÀà: ///
/// SubProtocol configuration ///
public class SubProtocolConfig : ConfigurationElement {
//Configuration attributes }
///
/// SubProtocol configuation collection ///
[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
if (m_SubProtocols == null) {
if(Logger.IsErrorEnabled)
Logger.Error(\required!\
return false; }
return true; } }
·þÎñÆ÷ÅäÖÃÈȸüÐÂ
Keywords: ÅäÖÃ,ÈȸüÐÂ
´Ë¹¦ÄÜÄܹ»ÔÊÐíÄãÔÚ²»ÖØÆô·þÎñÆ÷µÄǰÌáϸüзþÎñÆ÷ʵÀýµÄÅäÖᣠ(½öÏÞ1.6.5¼°ÆäÒÔÉϰ汾)
Ö§³ÖÈȸüеķþÎñÆ÷ʵÀýÅäÖÃÑ¡Ïî
SuperSocket Ö§³ÖÒÔÏÂÅäÖÃÑ¡ÏîµÄÈȸüÐÂ: * logCommand
* idleSessionTimeOut * maxRequestLength * logBasicSessionActivity * logAllSocketException
SuperSocket Ö§³ÖËùÓÐ×Ô¶¨ÒåÅäÖÃÊôÐÔºÍ×Ô¶¨ÒåÅäÖÃ×Ó½ÚµãµÄÈȸüС£ ÏÂÃæµÄ´úÂ뽫ÑÝʾÈçºÎÈÃÄãµÄ×Ô¶¨ÒåÅäÖÃÖ§³ÖÈȸüÐÂ: public class PushServer : AppServer {
private int m_Interval;
protected override bool Setup(IRootConfig rootConfig, IServerConfig config) {
RegisterConfigHandler(config, \ {
// the code in this scope will be executed automatically // after the configuration attribute \
var interval = 0;
int.TryParse(value, out interval);
if (interval <= 0)
interval = 60;// 60 seconds by default
m_Interval = interval * 1000; return true; });
return true; }
/// Other code }
Äã¿ÉÒÔÔÚQuickStartÖÐµÄ PushServer ÏîÄ¿ÖÐÕÒµ½´Ë¸üÄܵÄÍêÕûʾÀý´úÂë¡£
ÃüÁî¹ýÂËÆ÷
¹Ø¼ü×Ö: ÃüÁî¹ýÂËÆ÷, ÃüÁî, ¹ýÂËÆ÷, OnCommandExecuting, OnCommandExecuted
SuperSocket ÖеÄÃüÁî¹ýÂËÆ÷¿´ÆðÀ´ÓÐЩÏñ ASP.NET MVC ÖÐµÄ Action Filter£¬Äã¿ÉÒÔÓÃËüÀ´×öÃüÁîÖ´ÐеÄÀ¹½Ø£¬ÃüÁî¹ýÂËÆ÷»áÔÚÃüÁîÖ´ÐÐǰºÍÖ´Ðк󱻵÷ÓᣠÃüÁî¹ýÂËÆ÷±ØÐë¼Ì³ÐÓÚ Attribute Àà CommandFilterAttribute: ///
/// Command filter attribute ///
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] public abstract class CommandFilterAttribute : Attribute {
///
/// Gets or sets the execution order. /// ///
public int Order { get; set; } ///
/// Called when [command executing]. ///
///
public abstract void OnCommandExecuting(CommandExecutingContext commandContext); ///
/// Called when [command executed]. ///
///
public abstract void OnCommandExecuted(CommandExecutingContext commandContext); }
ÄãÐèҪΪÄãµÄÃüÁî¹ýÂËÆ÷ʵÏÖÏÂÃæÁ½¸ö·½·¨:
OnCommandExecuting: ´Ë·½·¨½«ÔÚÃüÁîÖ´ÐÐǰ±»µ÷ÓÃ; OnCommandExecuted: ´Ë·½·¨½«ÔÚÃüÁîÖ´Ðк󱻵÷ÓÃ; Order: ´ËÊôÐÔÓÃÓÚÉèÖöà¸öÃüÁî¹ýÂËÆ÷µÄÖ´ÐÐ˳Ðò;
ÏÂÃæµÄ´úÂ붨ÒåÁËÒ»¸öÃüÁî¹ýÂËÆ÷ LogTimeCommandFilterAttribute ÓÃÓڼǼִÐÐʱ¼ä³¬¹ý5ÃëÖÓµÄÃüÁî:
public class LogTimeCommandFilter : CommandFilterAttribute {
public override void OnCommandExecuting(CommandExecutingContext commandContext) {
commandContext.Session.Items[\ }
public override void OnCommandExecuted(CommandExecutingContext commandContext)