第一个函数

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. HDU_1506_Largest Rectangle in a Histogram_dp

    Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  2. R语言学习 - 热图美化

    实际应用中,异常值的出现会毁掉一张热图.这通常不是我们想要的.为了更好的可视化效果,需要对数据做些预处理,主要有对数转换,Z-score转换,抹去异常值,非线性颜色等方式. 对数转换 为了方便描述,假 ...

  3. CAD使用SetxDataDouble写数据(网页版)

    主要用到函数说明: MxDrawEntity::SetxDataDouble 写一个Double扩展数据,详细说明如下: 参数 说明 [in] BSTR val 字符串值 szAppName 扩展数据 ...

  4. SpringBoot项目编译后没有xxxmapper.xml文件解决方法

    在pom.xml文件中添加如下代码 <build> <plugins> <plugin> <groupId>org.springframework.bo ...

  5. 02JavaScript基础语法及数据类型

    JavaScript基础语法及数据类型 2.1数据类型 2.1.1字符串(String) 用单引号或双引号括起来的零个或多个单一的字符所组成. 2.1.2数值(Number) 包含整数或浮点数. 2. ...

  6. Leetcode747至少是其他数字两倍的最大数

    Leetcode747至少是其他数字两倍的最大数 在一个给定的数组nums中,总是存在一个最大元素 .查找数组中的最大元素是否至少是数组中每个其他数字的两倍.如果是,则返回最大元素的索引,否则返回-1 ...

  7. 面向对象程序设计--Java语言第一周编程题:分数

    分数 题目内容: 设计一个表示分数的类Fraction.这个类用两个int类型的变量分别表示分子和分母. 这个类的构造函数是: Fraction(int a, int b) 构造一个a/b的分数. 这 ...

  8. kdump机制和crash常见使用

    kdump简介 kdump是系统崩溃的时候,用来转储运行内存的一个工具. 系统一旦崩溃,内核就没法正常工作了,这个时候将由kdump提供一个用于捕获当前运行信息的内核, 该内核会将此时内存中的所有运行 ...

  9. 1043 输出PATest (20 分)

    题目链接:1043 输出PATest (20 分) 这道题目很简单,遍历整个字符串,统计相应字符的个数,然后按照题目要求进行输出即可. #include <bits/stdc++.h> u ...

  10. The King’s Ups and Downs(HDU 4489,动态规划递推,组合数,国王的游戏)

    题意: 给一个数字n,让1到n的所有数都以波浪形排序,即任意两个相邻的数都是一高一低或者一低一高 比如:1324   4231,再比如4213就是错的,因为4高,2低,接下来1就应该比2高,但是它没有 ...