コード例 #1
0
        static int Main(string[] args)
        {
            int port = 8000;
            var host = "localhost";

            for (var i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case "-host":
                    host = args[++i];
                    break;

                case "-port":
                    port = ushort.Parse(args[++i]);
                    break;

                case var other:
                    Console.Error.WriteLine("Unknown argument: {0}", other);
                    return(1);
                }
            }

            InitialiseData();
            Thread.Sleep(1000);
            Console.WriteLine("Connecting to server {0}:{1}", host, port);
            _Stats.Start();
            var client = new TcpClient(host, port);

            HandleConnection(client).Wait();
            return(0);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: nicodeslandes/LowLatency
        static async Task <int> Main(string[] args)
        {
            int port = 8000;
            var host = IPAddress.Any;

            for (var i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case "-host":
                    host = (await Dns.GetHostAddressesAsync(args[++i])).FirstOrDefault()
                           ?? throw new Exception($"Invalid hostname: {args[i]}");
                    break;

                case "-port":
                    port = ushort.Parse(args[++i]);
                    break;

                case var other:
                    Console.Error.WriteLine("Unknown argument: {0}", other);
                    return(1);
                }
            }

            Console.WriteLine($"Starting server on port {port}");
            _Stats.Start();
            var listener = new TcpListener(host, port);

            listener.Start();
            _ = AcceptClientConnections(listener);
            Console.WriteLine("Server started");
            Console.ReadLine();
            return(0);
        }