예제 #1
0
        private static void Main(string[] args)
        {
            IConfiguration config = new ConfigurationBuilder()
                                    .AddJsonFile("appsettings.json", false, true)
                                    .Build();

            var serverBuilder = new ServerBuilder()
                                .UseTcp(1000)
                                .UseUdp(1001)
                                .UseConfiguration <Settings>(config)
                                .ConfigureLogging(loggingBuilder =>
            {
                loggingBuilder.AddConfiguration(config.GetSection("Logging"));
                loggingBuilder.AddConsole();
            })
                                .RegisterTypes(serviceCollection =>
            {
                serviceCollection.AddSingleton <IPlayerService, PlayerService>();
            })
                                .RegisterPacketHandler <PlayerUpdatePacket, PlayerUpdatePacketHandler>()
                                .UseZeroFormatter();

            var server = serverBuilder.Build();

            server.Start();
        }
예제 #2
0
        public void Clone_WhenInstanceCloned_ThenInstancesAreEqual()
        {
            // arrange
            ServerBuilder builder = ServerBuilder.Create()
                                    .WithConnectionsAllowed(true)
                                    .WithHostname("server.domain.local")
                                    .WithIP("127.0.0.1")
                                    .WithLocation("location")
                                    .WithMaximumConnections(250)
                                    .WithName("name");

            Server instance0 = builder.Build();

            object instance1 = instance0.Clone();

            // act
            bool result = Equals(instance0, instance1);

            // assert
            Assert.That(instance0, Is.Not.Null);
            Assert.That(instance1, Is.Not.Null);
            Assert.That(instance1, Is.InstanceOf <Server>());
            Assert.That(ReferenceEquals(instance0, instance1), Is.Not.True);
            Assert.That(result, Is.True);
        }
예제 #3
0
        public void GetHashCode_WhenInstanceIsDeseraializeAndSerializedBack_ThenInstancesHashCodesAreEqual()
        {
            // arrange
            ServerBuilder builder = ServerBuilder.Create()
                                    .WithConnectionsAllowed(true)
                                    .WithHostname("server.domain.local")
                                    .WithIP("127.0.0.1")
                                    .WithLocation("location")
                                    .WithMaximumConnections(250)
                                    .WithName("name");

            Server instance0 = builder.Build();

            string serializedText = instance0.Serialize();

            Server instance1 = serializedText.Deserialize <Server>();

            // act
            int result0 = instance0.GetHashCode();
            int result1 = instance1.GetHashCode();

            // assert
            Assert.That(instance0, Is.Not.Null);
            Assert.That(instance1, Is.Not.Null);
            Assert.That(ReferenceEquals(instance0, instance1), Is.Not.True);
            Assert.That(Equals(result0, result1), Is.True);
        }
예제 #4
0
        public static void Main(string[] args)
        {
            // create a new AppBuilder
            IAppBuilder app = new AppBuilder();

            // init nowin's owin server factory.
            OwinServerFactory.Initialize(app.Properties);

            Configure(app);

            var          serverBuilder = new ServerBuilder();
            const string ip            = "127.0.0.1";
            const int    port          = 8888;

            serverBuilder.SetAddress(IPAddress.Parse(ip)).SetPort(port)
            .SetOwinApp(app.Build())
            .SetOwinCapabilities((IDictionary <string, object>)app.Properties[OwinKeys.ServerCapabilitiesKey]);

            using (var server = serverBuilder.Build()) {
                var serverRef = new WeakReference <INowinServer>(server);

                Task.Run(() => {
                    INowinServer nowinServer;
                    if (serverRef.TryGetTarget(out nowinServer))
                    {
                        nowinServer.Start();
                    }
                });

                var baseAddress = "http://" + ip + ":" + port + "/";
                Console.WriteLine("Nowin server listening {0}, press ENTER to exit.", baseAddress);

                Console.ReadLine();
            }
        }
예제 #5
0
        public void GetHashCode_WhenTwoDifferentInstancesAreCreated_ThenInstanceHashCodesAreNotEqual()
        {
            // arrange
            ServerBuilder builder = ServerBuilder.Create()
                                    .WithConnectionsAllowed(true)
                                    .WithHostname("server.domain.local")
                                    .WithIP("127.0.0.1")
                                    .WithLocation("location")
                                    .WithMaximumConnections(250)
                                    .WithName("name");

            ServerBuilder builder1 = ServerBuilder.Create()
                                     .WithConnectionsAllowed(true)
                                     .WithHostname("server.domain.local1")
                                     .WithIP("127.0.0.11")
                                     .WithLocation("location1")
                                     .WithMaximumConnections(250)
                                     .WithName("name1");

            Server instance0 = builder.Build();
            Server instance1 = builder1.Build();

            // act
            int result0 = instance0.GetHashCode();
            int result1 = instance1.GetHashCode();

            // assert
            Assert.That(instance0, Is.Not.Null);
            Assert.That(instance1, Is.Not.Null);
            Assert.That(ReferenceEquals(instance0, instance1), Is.Not.True);
            Assert.That(Equals(result0, result1), Is.False);
        }
예제 #6
0
        public LocalSetup()
        {
            var serverBuilder = new ServerBuilder().UseLocal().UseInMemory();

            server        = serverBuilder.Build();
            loginService  = LocalConnectionExtension.GetLoginService(server);
            clientBuilder = new ClientBuilder().UseLocal(server);
        }
예제 #7
0
        public GrpcLocalSetup()
        {
            const string host   = "localhost";
            var          port   = new Random().Next(5000, 10000);
            var          target = $"{host}:{port}";

            var serverBuilder = new ServerBuilder().UseGrpc(host, port).UseInMemory();

            clientBuilder = new ClientBuilder().UseGrpc(target, "localhost", 0);
            loginService  = GrpcConnectionExtension.GetLoginService(target);
            server        = serverBuilder.Build();
        }
예제 #8
0
        static void Main()
        {
            var builder = new ServerBuilder();

            builder.Add(new Logger());
            builder.OnMessageReceived += OnMessageReceived;
            var server = builder.Build();

            using var start = server.Start();
            Console.WriteLine("Press enter to exit.");
            Console.ReadLine();
        }
예제 #9
0
        static void Main(string[] args)
        {
            var app = new AppBuilder();

            OwinServerFactory.Initialize(app.Properties);

            app.UseWindsorContainer("windsor.config");

            var container     = app.GetWindsorContainer();
            var logMiddleware = container.Resolve <ConsoleLogMiddleware>();

            app.Use(logMiddleware);

            var options = container.Resolve <StaticFileMiddlewareOptions>();

            app.UseStaticFile(options);

            var startup = new Startup();

            startup.Configuration(app);

            var          builder = new ServerBuilder();
            const string ip      = "127.0.0.1";
            const int    port    = 8888;

            builder.SetAddress(IPAddress.Parse(ip)).SetPort(port)
            .SetOwinApp(app.Build())
            .SetOwinCapabilities((IDictionary <string, object>)app.Properties[OwinKeys.ServerCapabilitiesKey]);

            using (var server = builder.Build()) {
                var serverRef = new WeakReference <INowinServer>(server);

                Task.Run(() => {
                    INowinServer nowinServer;
                    if (serverRef.TryGetTarget(out nowinServer))
                    {
                        nowinServer.Start();
                    }
                });

                var baseAddress = "http://" + ip + ":" + port + "/";
                Console.WriteLine("Nowin server listening {0}, press ENTER to exit.", baseAddress);

                Console.ReadLine();
            }
        }
예제 #10
0
        static void Main(string[] args)
        {
            FileStream    fileStream = new FileStream("./servers.config.json", FileMode.Open, FileAccess.Read);
            ServerConfig  config     = ModelSerializer.ServerConfig(fileStream);
            ServerBuilder builder    = new ServerBuilder(config);

            controller = new ServerController(config);
            foreach (ServerManager server in controller.Config.Servers)
            {
                server.OutputData_Recived += Server_OutputData_Recived;
            }
            builder.BuildComplete += Builder_BuildComplete;
            builder.Build();
            while (!hasExited)
            {
                Console.ReadLine();
            }
        }
예제 #11
0
        private static INowinServer BuildNowinServer(IPAddress ip, int port)
        {
            // create a new AppBuilder
            var appBuilder = new AppBuilder();

            // init nowin's owin server factory.
            OwinServerFactory.Initialize(appBuilder.Properties);
            var startup = new Startup();

            startup.Configuration(appBuilder);
            // build server
            var serverBuilder = new ServerBuilder();
            var capabilities  = appBuilder.Properties[OwinKeys.ServerCapabilitiesKey];

            serverBuilder
            .SetAddress(ip)
            .SetPort(port)
            .SetOwinApp(appBuilder.Build())
            .SetOwinCapabilities((IDictionary <string, object>)capabilities);
            return(serverBuilder.Build());
        }
예제 #12
0
        public static void Main(string[] args)
        {
            // create a new AppBuilder
            IAppBuilder app = new AppBuilder();

            // init nowin's owin server factory.
            OwinServerFactory.Initialize(app.Properties);

            app.UseStaticFile(new StaticFileMiddlewareOptions {
                RootDirectory    = @"C:\inetpub\wwwroot",
                DefaultFile      = "iisstart.htm",
                EnableETag       = true,
                MimeTypeProvider = new MimeTypeProvider()
            });

            var          serverBuilder = new ServerBuilder();
            const string ip            = "127.0.0.1";
            const int    port          = 8888;

            serverBuilder.SetAddress(IPAddress.Parse(ip)).SetPort(port)
            .SetOwinApp(app.Build())
            .SetOwinCapabilities((IDictionary <string, object>)app.Properties[OwinKeys.ServerCapabilitiesKey]);

            using (var server = serverBuilder.Build()) {
                var serverRef = new WeakReference <INowinServer>(server);

                Task.Run(() => {
                    INowinServer nowinServer;
                    if (serverRef.TryGetTarget(out nowinServer))
                    {
                        nowinServer.Start();
                    }
                });

                var baseAddress = "http://" + ip + ":" + port + "/";
                Console.WriteLine("Nowin server listening {0}, press ENTER to exit.", baseAddress);

                Console.ReadLine();
            }
        }
예제 #13
0
        public static void Main(string[] args)
        {
            var appBuilder = new AppBuilder();

            Nowin.OwinServerFactory.Initialize(appBuilder.Properties);

            var startup = new Owin02_WebApi.Startup();

            startup.Configuration(appBuilder);

            var builder = new ServerBuilder();
            var ip      = "127.0.0.1";
            var port    = 8888;

            builder.SetAddress(System.Net.IPAddress.Parse(ip)).SetPort(port)
            .SetOwinApp(appBuilder.Build())
            .SetOwinCapabilities((IDictionary <string, object>)appBuilder.Properties[OwinKeys.ServerCapabilitiesKey]);

            using (var server = builder.Build()) {
                Task.Run(() => server.Start());

                var baseAddress = "http://" + ip + ":" + port + "/";
                Console.WriteLine("Nowin server listening " + baseAddress);

                var client = new HttpClient {
                    BaseAddress = new Uri(baseAddress, UriKind.Absolute)
                };

                var requestTask = client.GetAsync("api/values");
                requestTask.Wait();
                var response = requestTask.Result;
                Console.WriteLine(response);

                var readTask = response.Content.ReadAsStringAsync();
                readTask.Wait();
                Console.WriteLine(readTask.Result);

                Console.ReadLine();
            }
        }
예제 #14
0
        internal override void Execute(Program app)
        {
            var lf = new LoggerFactory();

            lf.AddNLog().ConfigureNLog(Program.NlogConfigFile);
            app._logger    = lf.CreateLogger("Chat.Server.Console");
            app._cmdlogger = lf.CreateLogger("Chat.Server.Console.Commands");
            GrpcConnectionExtension.SetLogger(lf);

            app.consoleOption = this;
            var builder = new ServerBuilder()
                          .UseLoggerFactory(lf)
                          .UseGrpc(Host, Port);

            if (Database == DbType.InMemory)
            {
                builder.UseInMemory();
            }
            else if (Database == DbType.SQLite)
            {
                builder.UseSQLite(SQLiteString);
            }
            app.server = builder.Build();
        }
예제 #15
0
        private static void StartRpcServer(CliArgs args)
        {
            // Create a factory used to instantiate all the service implementations
            // that are needed to initialize the server.
            Factory factory = new Factory("config/application.conf");

            // Build a gRPC server instance.
            ServerBuilder serverBuilder = ServerBuilder
                                          .ForPort(args.port)
                                          .ReportErrorDetails()
                                          .WithAccountService(factory.AccountService())
                                          .WithAccountLinkingService(factory.AccountLinkingService())
                                          .WithTransferService(factory.TransferService())
                                          .WithStorageService(factory.StorageService())
                                          .WithAccountManagementService(factory.AccountManagementService())
                                          .WithConsentManagementService(factory.ConsentManagementService())
                                          .WithNotificationService(factory.NotificationService());

            if (args.useSsl)
            {
                serverBuilder.WithTls(
                    "config/tls/cert.pem",
                    "config/tls/key.pem",
                    "config/tls/trusted-certs.pem");
            }

            RpcServer server = serverBuilder.Build();

            // You will need to Ctrl-C to exit.
            server.Start();
            logger.Info("Hit return to stop the server ");
            Console.ReadKey();
            logger.Info("Stopping the server....");
            server.Close();
            logger.Info("Server stopped");
        }
예제 #16
0
        public static async Task Main(string[] args)
        {
            SessionManager.Singleton.Start(1024 * 1024 * 4);
            // Manual wire up of the server
            var services = new ServiceCollection();

            services.AddLogging(builder =>
            {
                builder.SetMinimumLevel(LogLevel.Information);
                builder.AddConsole();
            });

            services.AddSignalR();

            var serviceProvider = services.BuildServiceProvider();

            var builder = new ServerBuilder(serviceProvider)
                          .UseSockets(sockets =>
            {
                // Echo server
                //sockets.ListenLocalhost(5000,
                //    builder => builder.UseConnectionLogging().UseConnectionHandler<EchoServerApplication>());

                //// HTTP/1.1 server
                //sockets.Listen(IPAddress.Loopback, 5001,
                //    builder => builder.UseConnectionLogging().UseConnectionHandler<HttpApplication>());

                //// SignalR Hub
                //sockets.Listen(IPAddress.Loopback, 5002,
                //    builder => builder.UseConnectionLogging().UseHub<Chat>());

                //// MQTT application
                //sockets.Listen(IPAddress.Loopback, 5003,
                //    builder => builder.UseConnectionLogging().UseConnectionHandler<MqttApplication>());

                //// Echo Server with TLS
                //sockets.Listen(IPAddress.Loopback, 5004,
                //    builder => builder.UseServerTls(options =>
                //    {
                //        options.LocalCertificate = new X509Certificate2("testcert.pfx", "testcert");

                //        // NOTE: Do not do this in a production environment
                //        options.AllowAnyRemoteCertificate();
                //    })
                //    .UseConnectionLogging().UseConnectionHandler<EchoServerApplication>());
                //IPAddress.Parse("172.21.0.17")
                //172.17.0.9
                sockets.Listen(IPAddress.Parse("172.17.0.9"), 36000,

                               builder => builder.UseConnectionHandler <MyCustomProtocol>());
            });

            builder.HeartBeatInterval = TimeSpan.FromSeconds(60);

            var server = builder.Build();



            var logger = serviceProvider.GetRequiredService <ILoggerFactory>().CreateLogger <Program>();

            await server.StartAsync();



            foreach (var ep in server.EndPoints)
            {
                Console.WriteLine("Listening on {0}.", ep);
            }

            var tcs = new TaskCompletionSource <object>();

            Console.CancelKeyPress += (sender, e) => tcs.TrySetResult(null);
            await tcs.Task;

            await server.StopAsync();

            SessionManager.Singleton.Stop();
        }
예제 #17
0
 public HttpClient Create()
 {
     return serverBuilder.Build().CreateClient();
 }