Пример #1
0
        private static void InitServer()
        {
            Configuration config      = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            int           port        = Convert.ToInt32(config.AppSettings.Settings["Port"].Value);
            int           parallelNum = Convert.ToInt32(config.AppSettings.Settings["ParallelNum"].Value);

            ConStr = config.AppSettings.Settings["ConnectionString"].Value;
            string strLissenIP = config.AppSettings.Settings["LissenIP"].Value;

            FileDirectory = config.AppSettings.Settings["FileDirectory"].Value;
            if (FileDirectory == "")
            {
                FileDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Files");
            }
            if (!Directory.Exists(FileDirectory))
            {
                Directory.CreateDirectory(FileDirectory);
            }

            int socketTimeOutMs = 0;

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

            AsyncSocketSvr = new AsyncSocketServer(parallelNum);
            AsyncSocketSvr.SocketTimeOutMS = socketTimeOutMs;
            AsyncSocketSvr.Init();

            IPEndPoint listenPoint = new IPEndPoint(IPAddress.Parse(strLissenIP), port);

            AsyncSocketSvr.Start(listenPoint);
        }
Пример #2
0
        private 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);

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

            ConStr        = config.AppSettings.Settings["ConnectionString"].Value;
            FileDirectory = config.AppSettings.Settings["FileDirectory"].Value;
            if (FileDirectory == "")
            {
                FileDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Files");
            }
            if (!Directory.Exists(FileDirectory))
            {
                Directory.CreateDirectory(FileDirectory);
            }
            int port = 0;

            if (!(int.TryParse(config.AppSettings.Settings["Port"].Value, out port)))
            {
                port = 9999;
            }
            int parallelNum = 0;

            if (!(int.TryParse(config.AppSettings.Settings["ParallelNum"].Value, out parallelNum)))
            {
                parallelNum = 8000;
            }
            int socketTimeOutMS = 0;

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

            Framework.Start();

            AsyncSocketSvr = new AsyncSocketServer(parallelNum);
            AsyncSocketSvr.SocketTimeOutMS = socketTimeOutMS;
            AsyncSocketSvr.Init();
            //IPEndPoint listenPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), port);
            // IPEndPoint listenPoint = new IPEndPoint(IPAddress.Parse("172.16.12.105"), port);172.16.6.114
            //IPEndPoint listenPoint = new IPEndPoint(IPAddress.Parse("172.16.6.113"), port);
            IPEndPoint listenPoint = new IPEndPoint(IPAddress.Parse("172.16.6.117"), port);

            //IPEndPoint listenPoint = new IPEndPoint(IPAddress.Parse("172.16.6.102"), port);
            //IPEndPoint listenPoint = new IPEndPoint(IPAddress.Parse("172.16.6.114"), port);
            AsyncSocketSvr.Start(listenPoint);

            //运行一个线程,监控全局队列的数目
            Analysis.Analisis();

            Console.WriteLine("Press any key to terminate the server process....");
            Console.ReadKey();
        }
Пример #3
0
        /// <summary>
        /// 开启Htpp 监听
        /// </summary>
        private void StartHttp()
        {
            IPAddress address = IPAddress.Any;
            //iocp.Start(59129);
            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);

            Configuration 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);
            }
            int port = 59129;

            if (!(int.TryParse(config.AppSettings.Settings["Port"].Value, out port)))
            {
                port = 59129;
            }
            int parallelNum = 0;

            if (!(int.TryParse(config.AppSettings.Settings["ParallelNum"].Value, out parallelNum)))
            {
                parallelNum = 8000;
            }
            int socketTimeOutMS = 0;

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

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

            AsyncSocketSvr.Start(listenPoint);

            // Console.WriteLine("Press any key to terminate the server process....");
            // Console.ReadKey();
            // http.Start(address, port, 10000);
        }
Пример #4
0
        /// <summary>
        /// 开启 监听
        /// </summary>
        public void StartServer()
        {
            writeLog       = new WriteLog("Log");
            Debug.WriteLog = writeLog;
            Console.WriteLine("...开始TCP监听");
            IPAddress address         = IPAddress.Any;
            int       port            = 8800;
            int       parallelNum     = 1000;
            int       socketTimeOutMS = 1000;

            AsyncSocketSvr                 = new AsyncSocketServer.AsyncSocketServer(parallelNum);
            AsyncSocketSvr.ServerLogic     = this;
            AsyncSocketSvr.SocketTimeOutMS = socketTimeOutMS;
            AsyncSocketSvr.Init();
            IPEndPoint listenPoint = new IPEndPoint(IPAddress.Any, port);

            AsyncSocketSvr.Start(listenPoint);
        }