/// <summary> /// start the server /// </summary> public void Run() { // initialze simple data members var maxConnections = 300; connectedAgents = new HashSet <IServerAgent>(); this.Add(this.LocalClient.GetDispatcher <ClientAgentSimulator>().ServerSimulator); // register server agent simulator var logfolder = $"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\\TAPALogs\\"; logfolder = "./logs/"; if (!Directory.Exists(logfolder)) { Directory.CreateDirectory(logfolder); } logger = new Logger(Name); transactionPool = new TransactionPool(); // configure ThreadPool var nWorkerThreads = 100; var nCompletionPortThreads = 10; ThreadPool.SetMinThreads(nWorkerThreads, nCompletionPortThreads); Console.WriteLine($"thread pool: {nWorkerThreads} worker threads, {nCompletionPortThreads} completion port threads."); // user management system Console.WriteLine($"{this.MailCenter.Count} user(s) registered."); // transaction pool, listen error event, register some transactions transactionPool.TransactionErrorEvent += TransactionErrorHandler; transactionPool.Register(Logger.IntelliUpdateConfiguration, 1000, "intelligently reconfigure loggers"); transactionPool.Register(Transaction_AgentsMonitor, 10, "connection monitor"); // configure socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); var ipAddr = IPAddress.Parse(IP.Trim()); var point = new IPEndPoint(ipAddr, this.Port); socket.Bind(point); socket.Listen(maxConnections); Console.WriteLine($"socket@{IP}:{this.Port}, OK."); // create socket listener thread listenThread = new Thread(__listen); listenThread.IsBackground = true; listenThread.Start(); logger.Write(LogType.PR, $"{this.Name}@{ipAddr}:{this.Port} is initilized."); }