Create a websocket server olny for .net core console application without using Asp .net core packages

3.4k views Asked by At

We need to migrate our application to .Net core and we had a dependency with a websocket library build for .Net Framework 3.5 . websocket-sharp

Until now i can not found a libray implementation for websocket that use only .Net Core not Asp Net core.

example of library with ASP are :

But we shall not use ASP packages juste to integrate à websocket implementation. Can anyone help me to find a websocket implementation using only .Net core layer not ASP.Net core ?

2

There are 2 answers

3
Sherif Elmetainy On

The abstract ClientWebSocketClass is an implementation for websockets that is not dependent on ASP.NET core. So you can do use that for client side communication with any websocket implemtnation.

The server side part will need an HTTP server since websocket connection are achieved by creating a normal HTTP request and the connection is upgraded to websocket. So you need a webserver to receive the initial request.

0
JamesHoux On

Here is a web socket server that does NOT depend on Kestrel or ASP, making it fully compatible with .NET Core and Mono.

https://github.com/jchristn/WatsonWebsocket

It should be very futureproof because of its minimal dependencies. Note that the author is a former Cisco Engineer with several other easy-to-use .net client/server libraries. I have used his other libraries with tremendous ease and success. He deserves support and respect for his efforts.

A big plus about his libraries is that they are quite minimal. They make getting up and running as easy as possible by offering only the most basic essentials you would want for servers and clients. Things like client-management, request routing, etc will depend on you to implement. I find this highly favorable.

UPDATE 11/7/2020: Joel has stated that he intends to rewrite the underlying portions of WatsonWebSocket so that it does not rely on HttpListener or http.sys. It will rely on his alternate custom http listener. This is great news because HttpListener is deprecated and has a sketchy future.

UPDATE 11/11/2023: Joel did not remove the portions depending on HttpListener because .NET 5 and forward have continued to fully support HttpListener. Watson WebSockets also still depends on http.sys, which seems to work fine on Linux. The only problem reports I've heard are that TLS/SSL does not work properly on Linux, but people work around this by running an Nginx server in front of their .NET app. I believe you'd have exactly the same issue with ASP.NET on Linux so no different.