第一个函数

d:\sourcecode\github\supersocket\quickstart\basic\telnetserver_startbyconfig\program.cs

 static void Main(string[] args)
{
Console.WriteLine("Press any key to start the server!"); Console.ReadKey();
Console.WriteLine(); var bootstrap = BootstrapFactory.CreateBootstrap(); if (!bootstrap.Initialize())
{
Console.WriteLine("Failed to initialize!");
Console.ReadKey();
return;
} var result = bootstrap.Start(); Console.WriteLine("Start result: {0}!", result); if (result == StartResult.Failed)
{
Console.WriteLine("Failed to start!");
Console.ReadKey();
return;
} Console.WriteLine("Press key 'q' to stop it!"); while (Console.ReadKey().KeyChar != 'q')
{
Console.WriteLine();
continue;
} Console.WriteLine(); //Stop the appServer
bootstrap.Stop(); Console.WriteLine("The server was stopped!");
}

第二个函数

d:\sourcecode\github\supersocket\socketengine\defaultbootstrap.cs

 /// <summary>
/// Starts this bootstrap.
/// </summary>
/// <returns></returns>
public StartResult Start()
{
if (!m_Initialized)
{
if (m_GlobalLog.IsErrorEnabled)
m_GlobalLog.Error("You cannot invoke method Start() before initializing!"); return StartResult.Failed;
} var result = StartResult.None; var succeeded = ; foreach (var server in m_AppServers)
{
if (!server.Start())
{
if (m_GlobalLog.IsErrorEnabled)
m_GlobalLog.InfoFormat("The server instance {0} has failed to be started!", server.Name);
}
else
{
succeeded++; if (Config.Isolation != IsolationMode.None)
{
if (m_GlobalLog.IsInfoEnabled)
m_GlobalLog.InfoFormat("The server instance {0} has been started!", server.Name);
}
}
} if (m_AppServers.Any())
{
if (m_AppServers.Count == succeeded)
result = StartResult.Success;
else if (succeeded == )
result = StartResult.Failed;
else
result = StartResult.PartialSuccess;
} if (m_PerfMonitor != null)
{
m_PerfMonitor.Start(); if (m_GlobalLog.IsDebugEnabled)
m_GlobalLog.Debug("The PerformanceMonitor has been started!");
} return result;
}

第三个函数

d:\sourcecode\github\supersocket\socketbase\appserver.cs

  /// <summary>
/// Starts this AppServer instance.
/// </summary>
/// <returns></returns>
public override bool Start()
{
if (!base.Start())
return false; if (!Config.DisableSessionSnapshot)
StartSessionSnapshotTimer(); if (Config.ClearIdleSession)
StartClearSessionTimer(); return true;
}

第四个函数

d:\sourcecode\github\supersocket\socketbase\appserverbase.cs

 /// <summary>
/// Starts this server instance.
/// </summary>
/// <returns>
/// return true if start successfull, else false
/// </returns>
public virtual bool Start()
{
var origStateCode = Interlocked.CompareExchange(ref m_StateCode, ServerStateConst.Starting, ServerStateConst.NotStarted); if (origStateCode != ServerStateConst.NotStarted)
{
if (origStateCode < ServerStateConst.NotStarted)
throw new Exception("You cannot start a server instance which has not been setup yet."); if (Logger.IsErrorEnabled)
Logger.ErrorFormat("This server instance is in the state {0}, you cannot start it now.", (ServerState)origStateCode); return false;
} if (!m_SocketServer.Start())
{
m_StateCode = ServerStateConst.NotStarted;
return false;
} StartedTime = DateTime.Now;
m_StateCode = ServerStateConst.Running; m_ServerStatus[StatusInfoKeys.IsRunning] = true;
m_ServerStatus[StatusInfoKeys.StartedTime] = StartedTime; try
{
//Will be removed in the next version
#pragma warning disable 0612, 618
OnStartup();
#pragma warning restore 0612, 618 OnStarted();
}
catch (Exception e)
{
if (Logger.IsErrorEnabled)
{
Logger.Error("One exception wa thrown in the method 'OnStartup()'.", e);
}
}
finally
{
if (Logger.IsInfoEnabled)
Logger.Info(string.Format("The server instance {0} has been started!", Name));
} return true;
}

第五个函数

D:\SourceCode\GitHub\SuperSocket\SocketEngine\AsyncSocketServer.cs

public override bool Start()
{
try
{
int bufferSize = AppServer.Config.ReceiveBufferSize; if (bufferSize <= )
bufferSize = * ; m_BufferManager = new BufferManager(bufferSize * AppServer.Config.MaxConnectionNumber, bufferSize); try
{
m_BufferManager.InitBuffer();
}
catch (Exception e)
{
AppServer.Logger.Error("Failed to allocate buffer for async socket communication, may because there is no enough memory, please decrease maxConnectionNumber in configuration!", e);
return false;
} // preallocate pool of SocketAsyncEventArgs objects
SocketAsyncEventArgs socketEventArg; var socketArgsProxyList = new List<SocketAsyncEventArgsProxy>(AppServer.Config.MaxConnectionNumber); for (int i = ; i < AppServer.Config.MaxConnectionNumber; i++)
{
//Pre-allocate a set of reusable SocketAsyncEventArgs
socketEventArg = new SocketAsyncEventArgs();
m_BufferManager.SetBuffer(socketEventArg); socketArgsProxyList.Add(new SocketAsyncEventArgsProxy(socketEventArg));
} m_ReadWritePool = new ConcurrentStack<SocketAsyncEventArgsProxy>(socketArgsProxyList); if (!base.Start())
return false; IsRunning = true;
return true;
}
catch (Exception e)
{
AppServer.Logger.Error(e);
return false;
}
}

第六个函数

d:\sourcecode\github\supersocket\socketengine\socketserverbase.cs

 public virtual bool Start()
{
IsStopped = false; ILog log = AppServer.Logger; var config = AppServer.Config; var sendingQueuePool = new SmartPool<SendingQueue>();
sendingQueuePool.Initialize(Math.Max(config.MaxConnectionNumber / , ),
Math.Max(config.MaxConnectionNumber * , ),
new SendingQueueSourceCreator(config.SendingQueueSize)); SendingQueuePool = sendingQueuePool; for (var i = ; i < ListenerInfos.Length; i++)
{
var listener = CreateListener(ListenerInfos[i]);
listener.Error += new ErrorHandler(OnListenerError);
listener.Stopped += new EventHandler(OnListenerStopped);
listener.NewClientAccepted += new NewClientAcceptHandler(OnNewClientAccepted); if (listener.Start(AppServer.Config))
{
Listeners.Add(listener); if (log.IsDebugEnabled)
{
log.DebugFormat("Listener ({0}) was started", listener.EndPoint);
}
}
else //If one listener failed to start, stop started listeners
{
if (log.IsDebugEnabled)
{
log.DebugFormat("Listener ({0}) failed to start", listener.EndPoint);
} for (var j = ; j < Listeners.Count; j++)
{
Listeners[j].Stop();
} Listeners.Clear();
return false;
}
} IsRunning = true;
return true;
}

第七个函数

D:\SourceCode\GitHub\SuperSocket\SocketEngine\TcpAsyncSocketListener.cs

/// <summary>
/// Starts to listen
/// </summary>
/// <param name="config">The server config.</param>
/// <returns></returns>
public override bool Start(IServerConfig config)
{
m_ListenSocket = new Socket(this.Info.EndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); try
{
m_ListenSocket.Bind(this.Info.EndPoint);
m_ListenSocket.Listen(m_ListenBackLog); m_ListenSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
m_ListenSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontLinger, true); SocketAsyncEventArgs acceptEventArg = new SocketAsyncEventArgs();
m_AcceptSAE = acceptEventArg;
acceptEventArg.Completed += new EventHandler<SocketAsyncEventArgs>(acceptEventArg_Completed); if (!m_ListenSocket.AcceptAsync(acceptEventArg))
ProcessAccept(acceptEventArg); return true; }
catch (Exception e)
{
OnError(e);
return false;
}
}

SuperSocket中的Server是如何初Start的的更多相关文章

  1. SuperSocket中的Server是如何初Initialize的

    第一个函数 d:\sourcecode\github\supersocket\quickstart\basic\telnetserver_startbyconfig\program.cs static ...

  2. SuperSocket中的Server的初始化和启动

    一.初始化的过程 static void Main(string[] args) { var bootstrap = BootstrapFactory.CreateBootstrap(); if (! ...

  3. win7中 SQL server 2005无法连接到服务器,错误码:18456

    win7中 SQL server 2005无法连接到服务器,错误码:18456.. 数据库刚装完.我用Windows登陆  结果登陆不上去.. 选中SQL Server Management Stud ...

  4. Asp.net中使用Server.HtmlDecode(string str)的使用

    前言: 在使用Visual Studio开发web页面时,需要在GridView中绑定Table数据,并加入了CommandField, 试图,点击详情按钮是,获取GridView中Rows中Cell ...

  5. servers中添加server时,看不到运行环境的选择。

    servers中添加server时,看不到运行环境的选择. 主要原因是tomcat目录中的配置文件格式不对.

  6. paip.java 开发中web server的选择jboss resin tomcat比较..

    paip.java 开发中web server的选择jboss resin tomcat比较.. 作者Attilax  艾龙, EMAIL:1466519819@qq.com 来源:attilax的专 ...

  7. Android系统进程间通信(IPC)机制Binder中的Server启动过程源代码分析

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6629298 在前面一篇文章浅谈Android系 ...

  8. Windows10中“SQL Server 配置管理器”哪去了?

    SQL Server 配置管理器是一种工具,用于管理与 SQL Server 相关联的服务.配置 SQL Server 使用的网络协议以及从 SQL Server 客户端计算机管理网络连接配置.SQL ...

  9. tomcat配置好后,启动eclipse中的server,不能出现有猫的页面,提示404

    原因:tomcat与eclipse中的server未关联起来 解决办法:双击servers中的server,在Server Locations中选中第二项,保存之后再进行刚才的操作就好了.

随机推荐

  1. re模块,正则表达式

    re模块 作用:取文本或者字符串内你所需要的东西 正则表达式的大致匹配过程是:依次拿出表达式和文本中的字符比较,如果每一个字符都能匹配,则匹配成功:一旦有匹配不成功的字符则匹配失败. ^叫做元字符,元 ...

  2. js读写txt文件

    view plain<script language="javascript" type="text/javascript"> //读文件funct ...

  3. vue过渡 & 动画---进入/离开 & 列表过渡

    (1)概述 Vue 在插入.更新或者移除 DOM 时,提供多种不同方式的应用过渡效果.包括以下工具: 在 CSS 过渡和动画中自动应用 class 可以配合使用第三方 CSS 动画库,如 Animat ...

  4. css--小白入门篇1

    一.引入 css用来描述html,学习css前我们先来学习html的基础标签的用法,再进入css的学习. 本教程面向小白对象,不会讲细枝末节深入的东西. 二.列表 列表有3种 2.1 无序列表 无序列 ...

  5. (C/C++学习)23.C++中指针的长度

    引言:先看下面一个程序会打印出什么? #include<iostream> using namespace std; int main() { int a = 2; int *p = &a ...

  6. Re0:DP学习之路 饭卡 HDU - 2546

    解法 01背包变式,首先贪心的想一下如果要保证余额最小那么就需要用相减后最小的钱减去之前最大的价格,且得保证这个钱在5元以上 对于寻找如何减最多能包含在5元以上,这里用01背包 我们把价钱看做体积装进 ...

  7. PKI相关知识简述

    1. 公钥泄露导致中间人攻击 有A.B.C三个人,如果C把自己的公钥提供给了AB双方,C伪装成B,让A认为C就B,这样A就把自己的公钥发送给C,C再伪装成A,让B认为C就A,B就把自己的公钥也发送给了 ...

  8. Spring Security核心类关系图

    以有限的脑力记忆无限的Knowledge,多画图,多画图,多画图. 核心类Authentication 和 GrantedAuthority AbstractAuthenticationToken 由 ...

  9. idea 获取当前git最新分支

    菜单栏VCS->选中Git 选择Fetch 获取最新分支

  10. 【10】AngularJS SQL

    AngularJS SQL 使用 PHP 从 MySQL 中获取数据 <div ng-app="myApp" ng-controller="customersCtr ...