Пример #1
0
        public void DoWork(object obj)
        {
            Singleton <Log> .Instance.WriteInfo("server peer launch");

            var are = (AutoResetEvent)obj;

            _Run = true;

            _Server.AcceptEvent += _Accept;
            _Server.Bind(_Port);

            while (_Run)
            {
                if (_Sockets.Count > 0)
                {
                    lock (_Sockets)
                    {
                        while (_Sockets.Count > 0)
                        {
                            var socket = _Sockets.Dequeue();

                            Singleton <Log> .Instance.WriteInfo(
                                string.Format("peer accept Remote {0} Local {1} .", socket.RemoteEndPoint, socket.LocalEndPoint));

                            var peer = new Peer(socket, _Protocol);

                            _Peers.Join(peer);

                            _CoreHandler.Push(peer.Binder, peer.Handler);
                        }
                    }
                }

                _AutoPowerRegulator.Operate();
            }

            _Peers.Release();


            _Server.AcceptEvent -= _Accept;
            _Server.Close();


            are.Set();
            Singleton <Log> .Instance.WriteInfo("server peer shutdown");
        }
Пример #2
0
 public void Close()
 {
     _Server.Close();
     _Enable = false;
 }