Beispiel #1
0
        static void Main()
        {
            ExceptionHandler();
            var currentTime = DateTime.Now;

            GlobalContext.Properties["LogDir"]      = currentTime.ToString("yyyyMM");
            GlobalContext.Properties["LogFileName"] = "_SocketAsyncServer" + currentTime.ToString("yyyyMMdd");
            Logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            FileDirectory = config.AppSettings.Settings["FileDirectory"].Value;
            if (FileDirectory == "")
            {
                FileDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Files");
            }
            if (!Directory.Exists(FileDirectory))
            {
                Directory.CreateDirectory(FileDirectory);
            }
            if (!(int.TryParse(config.AppSettings.Settings["ParallelNum"].Value, out var parallelNum)))
            {
                parallelNum = 8000;
            }

            if (!(int.TryParse(config.AppSettings.Settings["WaitResponseTimeOutMS"].Value, out var waitResponseTimeOutMs)))
            {
                waitResponseTimeOutMs = 1 * 60 * 1000;
            }

            if (!(int.TryParse(config.AppSettings.Settings["SocketTimeOutMS"].Value, out var socketTimeOutMs)))
            {
                socketTimeOutMs = 5 * 60 * 1000;
            }

            AsyncSocketSvr = new AsyncSocketServer(parallelNum)
            {
                WaitResponseTimeOutMs = waitResponseTimeOutMs,
                SocketTimeOutMs       = socketTimeOutMs
            };
            AsyncSocketSvr.Init();
            DevsManage.Init();

            EsProtocolMgr.Init();

            OutputLog = new WinLog();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            ThreadPool.SetMinThreads(200, 200);
            Application.Run(new MainForm());
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            DateTime currentTime = DateTime.Now;

            log4net.GlobalContext.Properties["LogDir"]      = currentTime.ToString("yyyyMM");
            log4net.GlobalContext.Properties["LogFileName"] = "_SocketAsyncServer" + currentTime.ToString("yyyyMMdd");
            Logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            //todo:性能测试
            int port = 0;

            port = 8103;
            int parallelNum = 100;

            parallelNum = 100;//并发数量
            int socketTimeOutMS = 0;

            socketTimeOutMS = 5 * 60 * 1000;

            Logger.Debug("for test");
            Logger.Info("for test info");
            Logger.Error("for test error");

            dm = new DataManager();

            AsyncSocketSvr = new AsyncSocketServer(parallelNum);
            AsyncSocketSvr.SocketTimeOutMS = socketTimeOutMS;
            AsyncSocketSvr.Init();
            IPEndPoint listenPoint = new IPEndPoint(GetIPAddress(), port);

            AsyncSocketSvr.Start(listenPoint);

            Console.WriteLine("Press any key to terminate the server process....");


            //for ring buffer test--begin--OK
            ///正式环境中,把SMELLsocketTest.cs/RingBufferManager.cs删除
            //    SMELLsocketTest sst = new SMELLsocketTest();
            //for ring buffer test--end--OK

            Console.ReadKey();
        }