第一个函数

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. vue项目国际化实现 vue-i18n使用详细教程

    1.安装vue-i18n: npm i vue-i18n -S 当然你也可以这样: <script src="https://unpkg.com/vue/dist/vue.js&quo ...

  2. 08Microsoft SQL Server 数据查询

    Microsoft SQL Server 数据查询 单表查询所有列 --查询所有行所有列 select all * from table; --查询不重复行的所有列 select distinct * ...

  3. crontab定时清理日志

    1.创建shell脚本 vi test_cron.sh #!/bin/bash#echo "====`date`====" >> /game/webapp/test_c ...

  4. 利用CMD 創建新文件的機種方法

    用 CMD 創建新文件 説明一下: 是在Windows的 CMD命令行模式下,或者在PowerShell命令行模式下創建新文件的機種方法. 創建空文件 cd.>a.txt cd.表示改变当前目录 ...

  5. Python学习-字符串函数操作3

    字符串函数操作 isprintable():判断一个字符串中所有字符是否都是可打印字符的. 与isspace()函数很相似 如果字符串中的所有字符都是可打印的字符或字符串为空返回 True,否则返回 ...

  6. Swing之登录界面

    import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Login extends JFrame ...

  7. SQL学习笔记:基础SQL语句

    目录 语句特点 进入数据库 基本查询语句 SELECT DISTINCT WHERE AND/OR/NOT :逻辑运算符 ORDER BY :排序 基本修改语句 INSERT:添加语句 UPDATE: ...

  8. 【模板】51nod 1051 最大子矩阵和

    [题解] 二重循环枚举起始列和终止列,竖着往下加,转化为一个最大子段和问题,逐行累加即可. #include<cstdio> #include<cstring> #includ ...

  9. 【Codeforces 486C】Palindrome Transformation

    [链接] 我是链接,点我呀:) [题意] 光标一开始在p的位置 你可以用上下左右四个键位移动光标(左右)或者更改光标所在的字符(上下增加或减少ascill码) 问你最少要操作多少次才能使得字符串变成回 ...

  10. HUD 1043 Eight 八数码问题 A*算法 1667 The Rotation Game IDA*算法

    先是这周是搜索的题,网站:http://acm.hdu.edu.cn/webcontest/contest_show.php?cid=6041 主要内容是BFS,A*,IDA*,还有一道K短路的,.. ...