Exemple #1
0
        protected virtual void Start(ISocketServerConfigure config)
        {
            if (config != null)
            {
                this._Config = config;
            }

            if (this._Config == null)
            {
                return;
            }

            _ServerSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            _ServerSock.Bind(new IPEndPoint(IPAddress.Any, this._Config.Port));     //  监听全部IP
            _ServerSock.Listen(_Config.Backlog);                                    //  排队数

            //建立socket连接的callback调用
            _ServerSock.BeginAccept(new AsyncCallback(OnConnectRequest), _ServerSock);

            AutoResetEvent autoEvent = new AutoResetEvent(false);

            _bwHeartListener      = new TimerCallback(this.StartHeartListening);
            _bwHeartListenerTimer = new Timer(_bwHeartListener, autoEvent, 1000, 500);

            if (MsgDeliver == null)
            {
                MsgDeliver = new MessageSender[this._Config.SendThreads];
            }

            for (int i = 0; i < MsgDeliver.Length; i++)
            {
                MsgDeliver[i] = new MessageSender();
                MsgDeliver[i].ShutDownClient += new ShutDownClientEventHandler(ShutdownClientEventHanlder);
            }

            Console.WriteLine("*** {0}(Port:{1}) Started {2} *** ", this._Config.ServerName, this._Config.Port, DateTime.Now.ToString("G"));
        }
        protected virtual void Start(ISocketServerConfigure config)
        {
            if (config != null)
                this._Config = config;

            if (this._Config == null)
                return;

            _ServerSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            _ServerSock.Bind(new IPEndPoint(IPAddress.Any, this._Config.Port));	    //  监听全部IP
            _ServerSock.Listen(_Config.Backlog);                                                    //  排队数

            //建立socket连接的callback调用
            _ServerSock.BeginAccept(new AsyncCallback(OnConnectRequest), _ServerSock);

            AutoResetEvent autoEvent = new AutoResetEvent(false);
            _bwHeartListener = new TimerCallback(this.StartHeartListening);
            _bwHeartListenerTimer = new Timer(_bwHeartListener, autoEvent, 1000, 500);

            if (MsgDeliver == null)
                MsgDeliver = new MessageSender[this._Config.SendThreads];

            for (int i = 0; i < MsgDeliver.Length; i++)
            {
                MsgDeliver[i] = new MessageSender();
                MsgDeliver[i].ShutDownClient += new ShutDownClientEventHandler(ShutdownClientEventHanlder);
            }

            Console.WriteLine("*** {0}(Port:{1}) Started {2} *** ", this._Config.ServerName, this._Config.Port, DateTime.Now.ToString("G"));
        }