예제 #1
0
        private void Initialize(int maxConnection)
        {
            _socketPool       = new EasyServerSocketPool(maxConnection);
            _accessController = new EasyServerAccessController(maxConnection);

            for (int i = 0; i < maxConnection; i++)
            {
                _socketPool.Push(new EasyServerSocket(_logger, SocketConfiguration, _socketPool, _accessController));
            }

            _logger?.LogInformation("Complete initialize server - max conn:{0}", maxConnection);
        }
예제 #2
0
        public override void Close()
        {
            try
            {
                Socket.Shutdown(SocketShutdown.Both);
            }
            catch (Exception)
            {
                _logger?.LogInformation("[{0}] Exception - Failed Shutdown method", SocketId);
            }

            SocketId = null;
            Socket.Close();
            Socket.Dispose();
            ReceiveSocketAsyncEventArgs.UserToken = null;
            Items.Clear();

            _socketPool.Push(this);
            _accessController.Release();

            _closedAction?.Invoke();
            _logger?.LogInformation("A client has been disconnected from the server. There are {0} clients connected to the server", _socketPool.GetCount());
        }