-
-
Save andrijac/c66d3593ef586d637c34ec1fdfd70380 to your computer and use it in GitHub Desktop.
Simple WS ASP.NET Core
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Hosting; | |
namespace SimpleWebSockets | |
{ | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
var host = new WebHostBuilder() | |
.UseKestrel() | |
.UseUrls("http://+:80") | |
.Configure(app => | |
{ | |
app.UseWebSockets(); | |
app.Run(async context => | |
{ | |
// Only support websocket requests | |
if (!context.WebSockets.IsWebSocketRequest) | |
{ | |
context.Response.StatusCode = 400; | |
return; | |
} | |
using (var webSocket = await context.WebSockets.AcceptWebSocketAsync()) | |
{ | |
// Do WebSocket things | |
} | |
}); | |
}) | |
.Build(); | |
host.Run(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment