コード例 #1
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseCors(builder => builder
                        .AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader());

            app.UseWebSockets();

            Server server = new Server();

            app.Use(async(context, next) =>
            {
                if (context.WebSockets.IsWebSocketRequest)
                {
                    WebSocket socket = await context.WebSockets.AcceptWebSocketAsync();

                    await server.ConnectNewClient(socket);
                }
                else
                {
                    await next();
                }
            });

            app.Run(async context =>
            {
                await context.Response.WriteAsync("Hello my beautiful friend from the internet <3");
            });
        }