private static async Task Main(string[] args)
        {
            // Build configuration
            var config = new ConfigurationBuilder();

            var baseDir = Directory.GetParent(AppContext.BaseDirectory);

            if (baseDir != null)
            {
                config.SetBasePath(baseDir.FullName);
            }
            config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false)
            .AddEnvironmentVariables();

            if (args != null)
            {
                config.AddCommandLine(args);
            }
            configuration = config.Build();

            //TestShutdown();

            int port = configuration.GetValue <int>("Port");
            //if (Environment.UserInteractive)
            //{
            //    using (var listener = new Socks5Listener(port))
            //    {
            //        Console.WriteLine($"Port: {listener.Port}");
            //        Task task = listener.ListenAsync(default);

            //        int left = Console.CursorLeft;
            //        int top = Console.CursorTop;
            //        while (!task.IsCompleted)
            //        {
            //            Console.SetCursorPosition(left, top);
            //            Console.WriteLine($"Connections: {listener.ConnectionsCount.ToString().PadRight(10)}");
            //            await Task.Delay(200);
            //        }
            //    }
            //}
            //else
            {
                using (var listener = new Socks5Listener(port))
                {
                    await listener.ListenAsync(CancellationToken.None);
                }
            }
        }
 public Socks5Connection(TcpClient tcp, Socks5Listener listener)
 {
     _managedTcp = new ManagedTcpSocket(tcp.Client);
     _listener   = listener;
 }