예제 #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseDefaultFiles();

            var provider = new FileExtensionContentTypeProvider();

            // Add new mappings
            provider.Mappings[".mtl"] = "text/plain";
            provider.Mappings[".obj"] = "text/plain";

            app.UseStaticFiles(new StaticFileOptions
            {
                ContentTypeProvider = provider
            });

            app.UseWebSockets();
            app.Use
                (async(context, next) =>
            {
                if (context.Request.Path == "/connect_client")
                {
                    if (context.WebSockets.IsWebSocketRequest)
                    {
                        WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync();

                        ClientView cs = new ClientView(webSocket);
                        DebugView ds  = new DebugView(webSocket);
                        simulationController.AddView(cs);
                        simulationController.AddView(ds);

                        await cs.StartReceiving();
                        simulationController.RemoveView(cs);
                    }
                    else
                    {
                        context.Response.StatusCode = 400;
                    }
                }
                else
                {
                    await next();
                }
            }
                );

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            //app.UseHttpsRedirection();
            //app.UseMvc();

            //app.UseDirectoryBrowser(new DirectoryBrowserOptions());
        }
예제 #2
0
        public Startup(IConfiguration configuration)
        {
            simulationController = new SimulationController();
            simulationController.AddModel(new WorldModel());
            simulationController.AddView(networkView);

            Configuration = configuration;
        }
예제 #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseDefaultFiles();

            var provider = new FileExtensionContentTypeProvider();

            // Add new mappings
            provider.Mappings[".mtl"] = "text/plain";
            provider.Mappings[".glb"] = "model/gltf-binary";
            provider.Mappings[".exr"] = "image/x-exr";

            app.UseStaticFiles(new StaticFileOptions
            {
                ContentTypeProvider = provider
            });

            WebSocketOptions options = new WebSocketOptions()
            {
                KeepAliveInterval = TimeSpan.FromMilliseconds(500),
                ReceiveBufferSize = 4 * 1024
            };

            app.UseWebSockets(options);
            app.Use(async(context, next) =>
            {
                if (context.Request.Path == "/connect_client")
                {
                    if (context.WebSockets.IsWebSocketRequest)
                    {
                        Console.WriteLine("Accepting Websocket...");
                        WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync();

                        ClientView clientView = new ClientView(webSocket);
                        simulationController.AddView(clientView);

                        clientView.Run();

                        simulationController.RemoveView(clientView);
                    }
                    else
                    {
                        context.Response.StatusCode = 400;
                    }
                }
                else
                {
                    await next();
                }
            });



            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                //app.UseHsts();
            }

            //app.UseHttpsRedirection();
            //app.UseMvc();

            //app.UseDirectoryBrowser(new DirectoryBrowserOptions());
        }