日期:2014-05-18 浏览次数:20451 次
static void Main(string[] args)
{
AppMain app = new AppMain();
// connStr = app.GetConnStr();
// Welcome and Start listening
app.log.WriteLog("*** ESP Server Started " + DateTime.Now.ToString( "G" ) + "***" , EventLogType.Information);
int nPortListen = app.GetPort();//7893;
app.GetBufferSize();
Socket listener = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
listener.Bind( new IPEndPoint( IPAddress.Any ,nPortListen ) );
listener.Listen( 500 );
app.log.WriteLog("Listening on : " + nPortListen , EventLogType.Information);
// app.StartMt();
listener.BeginAccept( new AsyncCallback( app.OnConnectRequest ), listener );
Console.WriteLine ("Press Enter to exit" );
Console.ReadLine();
app.log.WriteLog("Server is Closed",EventLogType.Information);
app.mas.Close();//关闭mas
// Clean up before we go home
try
{
app.workflag = false;
listener.Close();
app.rotation1.Abort();
int tol = app.m_aryClients.Count;
int i = 0;
while(i < tol )
{
SocketChatClient client = (SocketChatClient)app.m_aryClients[i];
client.Sock.Shutdown(SocketShutdown.Send);
client.SendIsVal = false;
i++;
app.m_aryClients.Remove(client);
}
}
catch(Exception e)
{
app.log.WriteLog(e,"关闭异常");
}
// Console.ReadLine();
}