/// <summary>
    /// 侦听客户端
    /// </summary>
    public AsyncIOCPServer(string IP, int portNo, int _maxClient)
    {
        instance = this;
        try
        {
            maxClient       = _maxClient;
            _Socket         = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            _Socket.NoDelay = true;
            hostEndPoint    = new IPEndPoint(IPAddress.Parse(IP), portNo);
            _Socket.Bind(hostEndPoint);
            _Socket.Listen(maxClient);

            Init();

            Thread tCheckClientHeartbeat = new Thread(CheckClientHeartbeat);
            tCheckClientHeartbeat.IsBackground = true;
            tCheckClientHeartbeat.Start();

            StartAccept(null);
            Log4Debug("初始化TCP Socket成功。");
        }
        catch (Exception error)
        {
            Log4Debug(error.Message);
        }
    }
Exemple #2
0
        /// <summary>
        /// 启动侦听
        /// </summary>
        /// <returns></returns>
        public static void StartLisen()
        {
            AsyncIOCPServer server = new AsyncIOCPServer(IPAddress.Parse(IpAddress), Port, MaxListenCount);

            server.Start();
            Console.WriteLine("Server Started:{0}:{1}!", IpAddress, Port);
            System.Console.ReadLine();
        }