This article appears in the Third party product review section. Articles in this section are provided only to members and are not allowed to be used by tool vendors to promote or advertise products in any way or form. Members are requested to report any spam or advertising.
Web projects often need to push data as fast as possible to customers, without waiting for client requests if necessary. A two-way communication mechanism is ideal for Web sites that communicate with users in real time, such as online communication or document collaboration tools, or to update system status on Long-running computing/execution servers.
Previously, such issues generally used the following solution:
Use the Socket connection in Flash (http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/Socket.html)
Ajax Long Polling (https://gist.github.com/jasdeepkhalsa/4353139)
Server Send Event ... (http://en.wikipedia.org/wiki/Server-sent_events)
... Or use IE in the classic Frame technology (http://cometdaily.com/2007/11/05/the-forever-frame-technique/)
But now we have a better choice: WebSocket. Its standards were released in 2011 and have been in place for some time in modern browsers. It is better because the use of safer and more mature protocols has brought improvements and upgrades.
Slightly note:
This comparison was made a few months ago and may not be timely enough, but if someone is looking for a good websocket library, I think it will still be useful to him.
This comparison is only for libraries that are published as NuGet packages, Superwebsocket, although using NuGet repository, needs to be downloaded from the Web page.
Maybe when I pull out, I'll compare the new library or the new version of the tested library and update this article.
Fleck
Https://github.com/statianzo/Fleck
I find this library really easy to use, for libraries, documents, examples, and so on, just add a library, copy the code in a few lines of example, and run--that's simple.
But simplicity comes at a price: its function is not powerful, and there are too few places to configure it.
private static void Main (string[] args)
{
var server = new Websocketserver ("ws://localhost:8181");
Server. Start (Socket =>
{
socket. OnOpen = () => OnOpen (socket);
Socket. OnClose = () => OnClose (socket);
Socket. OnMessage = M => OnMessage (socket, m);}
);
I use it for simple, fast projects, and if you don't need to use websocket to send too complex data structures, command-like messages, or alternative ways to support your client without websocket, that's what you want.
Advantages:
Simple
No dependencies
Disadvantages:
Less configurable items
Client browsers don't support WebSocket when it's over.
Signalr
Http://www.asp.net/signalr
Microsoft's production is the biggest advantage I think the library has. It has been integrated with the existing ASP.net framework and has done a good job of abstracting the server side and client code, which means you don't need to get too deep into the protocol. It can then be smart enough to automatically use other communication mechanisms when the client browser does not support WebSocket. It can also accomplish something called Remote Procedure Call (RPC), from the server to the client.