Пример #1
0
 public void Configure(IApplicationBuilder app)
 {
     app
     .UseWebSockets(new WebSocketOptions {
         KeepAliveInterval = Settings.WsPingInterval
     })
     .Use((ctx, next) => ctx.WebSockets.IsWebSocketRequest ? WsHandler.TryProcessWebSocketRequest(ctx) : next())
     .UseDefaultFiles(new DefaultFilesOptions {
         DefaultFileNames = new List <string>(1)
         {
             "index.html"
         }
     })
     .UseStaticFiles(new StaticFileOptions {
         OnPrepareResponse = ctx => ctx.Context.Response.Headers.Append("Cache-Control", "public, max-age=600")
     })
     .UseRouter(
         new RouteBuilder(app)
         .MapPut("send", ctx => ProcessRequest(ctx, IncomingCallHandler.ProcessRequest))
         .MapGet("find", ctx => ProcessRequest(ctx, TransmissionInfoHandler.ProcessRequest))
         .Build())
     .Run(ctx =>
     {
         ctx.Response.StatusCode = 404;
         return(ctx.Response.WriteAsync("File Not Found"));
     });
 }
Пример #2
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, WsHandler wsHandler)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            // 处理http请求
            app.UseMvc();
            // 处理WebSocket请求
            var webSocketOptions = new WebSocketOptions()
            {
                KeepAliveInterval = TimeSpan.FromSeconds(120),
                ReceiveBufferSize = 4 * 1024
            };

            app.UseWebSockets(webSocketOptions);
            app.Use(wsHandler.WebSocktHandlerAsync);
        }
Пример #3
0
        public async Task <IActionResult> Get(int id, [FromQuery] string code, [FromQuery] int?state, [FromServices] WsHandler wsHandler)
        {
            // 网页通知
            await wsHandler.OrderNotifyAsync(id, code, state ?? 99);

            // 客户端通知
            //var state = StateObject.DicSocket.FirstOrDefault(a => a.Key == id);
            //if (state.Value != null)
            //{
            //    if (!state.Value.workSocket.Poll(10, System.Net.Sockets.SelectMode.SelectRead))
            //    {
            //        AsynchronousSocketListener.Send(state.Value, code);
            //    }
            //    else
            //    {
            //        StateObject.DicSocket.Remove(id);
            //    }
            //}
            return(Ok("新订单通知成功"));
        }