示例#1
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            int    port    = 8001;
            String address = "127.0.0.1";
            var    portStr = Environment.GetEnvironmentVariable("CLUSTER_PORT");
            var    dnsName = Environment.GetEnvironmentVariable("CLUSTER_IP");

            if (!string.IsNullOrEmpty(portStr))
            {
                port = int.Parse(portStr);
                logger.LogInformation($"Port: {port}");
            }

            if (!string.IsNullOrEmpty(dnsName))
            {
                address = dnsName;

                logger.LogInformation($"Dns: {address}");
            }



            TCPNetworkLib.TCPServer server = new TCPNetworkLib.TCPServer(5, 2048);
            server.Init();

            // Get IPv4 address
            IPAddress  ipAddress = GetIPAddress(address, AddressFamily.InterNetwork);
            IPEndPoint endPoint  = new IPEndPoint(ipAddress, port);

            server.Start(endPoint);
            await Task.Delay(0);
        }
示例#2
0
        static void Main(String[] _args)
        {
            String address = "localhost";
            int    port    = 8001;

            TCPNetworkLib.TCPServer server = new TCPNetworkLib.TCPServer(5, 2048);
            server.Init();

            // Get IPv4 address
            IPAddress  ipAddress = GetIPAddress(address, AddressFamily.InterNetwork);
            IPEndPoint endPoint  = new IPEndPoint(ipAddress, port);

            server.Start(endPoint);
        }