using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace WebSocket
{
public class WebSocketMiddleware
{
private readonly RequestDelegate _next;
///
/// 构造
///
///
/// 目标路径
public WebSocketMiddleware(RequestDelegate next)
{
_next = next;
}
///
/// 中间件调用
///
///
///
public async Task Invoke(HttpContext httpContext)
{
try
{
var socket = await httpContext.WebSockets.AcceptWebSocketAsync();
await new WebSocketHelper().WebSocketReceive(socket);
}
catch (Exception)
{
}
await _next(httpContext);
}
}
}