共用方式為


I need to implement a WebSocket Server, what should I use?

In one of those typical "geeks coffee breaking" we went into a discussion about a scenario where someone needs to develop today a WebSocket Server, what would be the best approach to do it?

That's a great topic of conversation to be having around the coffee machine, right? Who does not love a good discussion around WebSockets Servers?

Basically our discussion was started around the technology you would you advise: ASP.NET, ASP.NET Core or Self-Hosted for example in a windows service? And bringing into the picture characteristics such as Scalability and Availability?

We went back and forward it those typical approaches (ASP.NET vs Self Hosted), when someone throw in the air:

 

How about SignalR on Core?

After this, the discussion, really got interesting.

So, my take on this was that the problem with the SignalR on core is that it does not have PersistenConnections anymore to build your own WebSocket server. ☹
However using Microsoft.AspNetCore.Sockets library which SignalR is using for their Hubs implementation, would be a valid and interesting way to go.In fact SignalR is a very specific use-case for WebSockets with a specific pub-sub protocol which may not work for all scenarios, so using the underlying library might be a good approach.

Here is a web example of using SignalR in ASP.NET Core 2 to track multiple aircraft positions on a map:

SignalR in ASP.NET Core 2

I also believe that another possible approach that we could use, would be using Fleck (WebSocket server implementation in C#, available also as a NuGet Package)

C# Websocket Implementation

This was branched from the Nugget project (on CodePlex), it requires no inheritance, container, or additional references, pretty cool.

And that's it, hopefully this references would might help someone in getting a valuable insight about the possible approaches when starting a new solution where you will have the need to develop a WebSocket Server, only try to think out of the box and do not get stuck on the usual stuff.

Hope that helps

Comments