Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET WebSocket client and server library

Tags:

c#

.net

websocket

I'm looking for an open source, cross-platform, actively maintained .NET library which provides websocket functionality for both clients and servers, in such a way that most of the code (after connection is established) can use the same abstraction regardless of which side of the connection it is on. Ideally, it would be a platform-independent implementation of System.Net.WebSockets, but I don't really care if it defines its own types, so long as there's some single abstract WebSocket class that can be shared by client and server code.

Things that I've looked at and that did not qualify (but correct me if I'm wrong):

  • System.Net.WebSockets (client only, Win8+ only)
  • WebSocket4Net (client only)
  • WebSocket Portable (client only)
  • Fleck (server only)
  • WebSocketListener (server only)
  • SuperWebSocket (server only)
  • Owin.WebSocket (server only)
  • PowerWebSockets (proprietary)
  • XSockets (proprietary)
  • Alchemy Websockets (last release in 2012, many active bugs in the tracker with no answers)

The only one that I could find that seems to be matching the requirements is websocket-sharp. However, what worries me there is the sheer number of opened issues in the tracker along the lines of clients unable to connect, invalid data frames etc - it sounds like it's not very mature yet.

Are there any other candidates that match my requirements that I have missed? Or am I wrong about any of the libraries listed above being client/server only?

like image 875
Pavel Minaev Avatar asked Nov 01 '15 20:11

Pavel Minaev


2 Answers

Look at Microsoft's SignalR. SignalR is a higher level abstraction around websockets. SignalR also allows the client to be written in .NET (C#). From the SignalR documentation:

The SignalR Hubs API enables you to make remote procedure calls (RPCs) from a server to connected clients and from clients to the server. In server code, you define methods that can be called by clients, and you call methods that run on the client. In client code, you define methods that can be called from the server, and you call methods that run on the server. SignalR takes care of all of the client-to-server plumbing for you.

SignalR also offers a lower-level API called Persistent Connections. For an introduction to SignalR, Hubs, and Persistent Connections, or for a tutorial that shows how to build a complete SignalR application, see SignalR - Getting Started.

like image 123
Jared Dykstra Avatar answered Oct 07 '22 23:10

Jared Dykstra


One another solution is to make use of Edge.js. This is a .NET library that utilizes Node.js. You could let Node.js to act as both the server and client of the WebSocket channel. And then utilize Edge.js to act as the bridge between the worlds, Nodejs and the .Net. Have a look at the following, there are plenty of samples as well. github.com/tjanczuk/edge/tree/master#scripting-clr-from-nodejs. Both are excellent frameworks that are actively maintained.

However the use of Edge.js does introduce an additional dependency, node.js

like image 22
Don Avatar answered Oct 07 '22 23:10

Don