From 9d585fc0a0f1982a4b4d0d3e4610db2a141601a3 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 26 Nov 2024 17:03:50 -0800 Subject: [PATCH] Remove Nowin WebSocket sample --- aspnetcore/fundamentals/owin.md | 52 --------------------------------- 1 file changed, 52 deletions(-) diff --git a/aspnetcore/fundamentals/owin.md b/aspnetcore/fundamentals/owin.md index 2d6f7fc6ee9f..2eaa14ba7bba 100644 --- a/aspnetcore/fundamentals/owin.md +++ b/aspnetcore/fundamentals/owin.md @@ -90,58 +90,6 @@ app.UseOwin(pipeline => }); ``` - - -## Run ASP.NET Core on an OWIN-based server and use its WebSockets support - -Another example of how OWIN-based servers' features can be leveraged by ASP.NET Core is access to features like WebSockets. The .NET OWIN web server used in the previous example has support for WebSockets built in, which can be leveraged by an ASP.NET Core application. The example below shows a simple web app that supports WebSockets and echoes back everything sent to the server through WebSockets. - -```csharp -public class Startup -{ - public void Configure(IApplicationBuilder app) - { - app.Use(async (context, next) => - { - if (context.WebSockets.IsWebSocketRequest) - { - WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync(); - await EchoWebSocket(webSocket); - } - else - { - await next(); - } - }); - - app.Run(context => - { - return context.Response.WriteAsync("Hello World"); - }); - } - - private async Task EchoWebSocket(WebSocket webSocket) - { - byte[] buffer = new byte[1024]; - WebSocketReceiveResult received = await webSocket.ReceiveAsync( - new ArraySegment(buffer), CancellationToken.None); - - while (!webSocket.CloseStatus.HasValue) - { - // Echo anything we receive - await webSocket.SendAsync(new ArraySegment(buffer, 0, received.Count), - received.MessageType, received.EndOfMessage, CancellationToken.None); - - received = await webSocket.ReceiveAsync(new ArraySegment(buffer), - CancellationToken.None); - } - - await webSocket.CloseAsync(webSocket.CloseStatus.Value, - webSocket.CloseStatusDescription, CancellationToken.None); - } -} -``` - ## OWIN environment You can construct an OWIN environment using the `HttpContext`.