public TaskManager(ConnectionPool pool) { this.Pool = pool; }
//监听客户端的连接,并创建一个发消息实体 public static void StartListening1() { Console.Write("****************************************************\n"); Console.Write("** " + lg.ServerSocket_ServerSocket_GMTools_Title + " **\n"); Console.Write("****************************************************\n"); //Thread thread = new Thread(new ThreadStart(receiverThread)); //thread.Start(); //初始化XML文件 ReadXMLFile xmlFiles = new ReadXMLFile(); //IPAddress ipAddress = Dns.Resolve(xmlFiles.ServerIP).AddressList[0]; IPAddress ipAddress = IPAddress.Parse(xmlFiles.ServerIP); //初始化数据库连接参数值 SqlHelper helper = new SqlHelper(); helper.init(xmlFiles.DatabaseIP, xmlFiles.DBName, xmlFiles.UserName, xmlFiles.PassWord); IPEndPoint ipLocalEndPoint = new IPEndPoint(ipAddress, xmlFiles.ServerPort); TaskManager ClientTask; // Client Connections Pool ConnectionPool ConnectionPool = new ConnectionPool(); // Client Task to handle client requests ClientTask = new TaskManager(ConnectionPool); ClientTask.Start(); TcpListener listener = new TcpListener(ipLocalEndPoint); try { listener.Start(); int clientCycle = xmlFiles.ServerCnt; int ClientNbr = 0; // Start listening for connections. Console.WriteLine(lg.ServerSocket_ServerSocket_GMTools_Port + xmlFiles.ServerPort); HandlerManager handlers = new HandlerManager(); while (clientCycle > 0) { TcpClient handler = listener.AcceptTcpClient(); if (handler != null) { Console.WriteLine(lg.ServerSocket_ServerSocket_GMTools_Accept + lg.ServerSocket_ServerSocket_GMTools_Client + "#{0}!", ++ClientNbr); Console.WriteLine(lg.ServerSocket_ServerSocket_GMTools_Validate); handlers.registerHandler(new Handler(handler)); // An incoming connection needs to be processed. ConnectionPool.Enqueue(new Handler(handler)); //--clientCycle ; } else { Console.WriteLine(lg.ServerSocket_ServerSocket_GMTools_Client + "#{0}" + lg.ServerSocket_Handler_UserLeft, ClientNbr); break; } } listener.Stop(); ClientTask.Stop(); UserInfoAPI userAPI = new UserInfoAPI(); userAPI.GM_UpdateActiveUser(1, 0); } catch (IOException e) { Console.WriteLine(e.ToString()); } catch (SocketException ex) { Console.WriteLine(ex.Message); } Console.WriteLine("\nHit enter to continue..."); Console.Read(); }