Example #1
0
        /// <summary>
        /// The entry point of the program, where the program control starts and ends.
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        /// <returns>The exit code that is given to the operating system after the program ends.</returns>
        public static int Main(string[] args)
        {
            var cfg = new Config();

            if (!Config.Parse(args.ToList(), cfg))
            {
                return(-1);
            }

            var channelserver = new NetworkChannelServer(new IPEndPoint(cfg.Adapter, cfg.Port));

            Console.WriteLine("Running server ...");
            channelserver.RunAsync().WaitForTaskOrThrow();

            return(0);
        }
Example #2
0
        /// <summary>
        /// Runs a channel server in the current process
        /// </summary>
        /// <returns>The awaitable task for server exit.</returns>
        /// <param name="token">A cancellationtoken for stopping the server.</param>
        /// <param name="host">The hostname to use.</param>
        /// <param name="port">The port to use.</param>
        /// <param name="configureclient"><c>True</c> if the client config should be set automatically</param>
        public static Task HostServer(CancellationToken token, string host = "localhost", int port = 8888, bool configureclient = true)
        {
            var addr =
                string.Equals("localhost", host, StringComparison.InvariantCultureIgnoreCase) || string.Equals("127.0.0.1", host, StringComparison.InvariantCultureIgnoreCase)
                                ? System.Net.IPAddress.Loopback
                                : System.Net.IPAddress.Any;

            var channelserver = new NetworkChannelServer(new System.Net.IPEndPoint(addr, port));

            if (configureclient)
            {
                NetworkConfig.Configure(host, port, true);
            }

            if (token.CanBeCanceled)
            {
                token.Register(() => {
                    channelserver.Dispose();
                });
            }

            return(channelserver.RunAsync());
        }