. NET WebSocket Development Package Comparison

Source: Internet
Author: User
Tags net websocket

Web projects often need to push data to customers as quickly as possible, without waiting for client requests when necessary. A two-way communication mechanism is ideal for sites that communicate with users in real time, such as online communication or document collaboration tools, or to update system state on long-running compute/execution servers.

Previously, this type of problem generally used the following solution:

    • Using 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 just use the classic Frame technology in IE (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 implemented in modern browsers for some time. It is better to use more secure and mature protocols, bringing improvements and upgrades.

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 for him.

This comparison is only for libraries published as NuGet packages, although Superwebsocket uses NuGet repository, but needs to be downloaded from a Web page.

Maybe when I'm done, I'll use the new library or the new version of the tested library to compare and update this post.

Fleck

Https://github.com/statianzo/Fleck

I found that this library is really easy to use, for libraries, documents, examples, and so on, just add libraries, copy the code from a few lines of examples, and then run-it's that simple.

But simplicity comes at a price: it's not powerful, and there are too few places to configure.

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); });}

For a quick and easy project I will use it, if you do not need to use websocket to send too complex data structures, command-like messages, or the client without WebSocket support when the alternative way, this is what you want.

Advantages:

    • Simple

    • No dependencies

Disadvantages:

    • Less configurable items

    • The client browser does not support WebSocket when it's over.

SignalR

Http://www.asp.net/signalr

The Microsoft production is I think this library biggest merit. 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 to automatically use other communication mechanisms when the client browser does not support WebSocket. It can also accomplish something called a Remote Procedure call (RPC), from the server to the client.

It can broadcast messages to all clients, and can be sent to designated users individually. The processing of a large number of concurrent connections is also excellent. And--It's open source!

Sounds great, doesn't it? But... It needs IIS8 or Windows Server (WINDOWS8), but I'm sure you won't run a big project on Win8. For me, this is the cool feature of "a new generation of Microsoft's worth of operating systems". It's good to develop an enterprise project, but for small projects, buying an operating system for this open source Library--it's too expensive.

Of course these environments are websocket must require. This article is about websocket communication, so I counted this as a big drawback.

public class myhub1:hub{public void Send (string name, String message) {//Call the Broadcastmessage Metho        D to update clients.    Clients.All.broadcastMessage (name, message); }}

$ (function () {var chat = $.connection.myhub1;    Chat.client.broadcastMessage = function (name, message) {//...}; $.connection.hub.start (). Done (function () {$ (' #sendmessage '). Click (function () {Chat.server.send (' mess        Age ');    }); });});

Advantages:

    • Very good abstraction.

    • Tightly integrated with IIS and ASP.

    • Many candidate ways

    • Open source

    • Microsoft Official Library

    • Scalability is good

Disadvantages:

    • Need IIS8 ...

    • ... That is, Windows Server 2012 is too expensive.

Alchemywebsocket

http://alchemywebsockets.net/

When I think of WebSocket library, this is incredible. Yes, that's true. It can be lined up behind Fleck, it's very easy to use, easy to install (NuGet packages available), and the documentation contains good examples.

It includes both the server and the client, as well as scalability

Static void main (String[] args) {    //  Create a new server -  Accept port and IP range,    //  Setup method     var aServer = new  Websocketserver (81, ipaddress.any)     {         OnReceive = OnReceive,        OnSend =  onsend,        onconnect = onconnect,         OnConnected = OnConnected,         ondisconnect = ondisconnect,        timeout =  new timespan (0, 5, 0)     };    aserver.start ();     string consoleReadLine;    do    {          Consolereadline = console.readline ();         sockets. ForEach (S => s.send (consolereadline));    } while  (consoleReadLine  !=  "Exit");}

But it has some awkward, I can't avoid. For example there is no simple event method "OnReceive", only a string, in fact the message is sent on the client. You have to do it yourself. Yes, you have to call, and you can only call. ToString () to get the real message, but the purpose of using the library is to not force itself to implement the communication protocol.

private static void OnReceive (UserContext context) {Console.WriteLine ("Client" + context. Clientaddress.tostring () + "sended:" + context. Dataframe.tostring ());}

The WebSocket server initialization method first receives the port and then the IP setting. I always thought that the expression of the address should be the first IP then the port, and only when it is necessary to specify the port. There is also a timeout setting: Why does it have to be timed out? I can understand that this can sometimes be useful, but it should not be one of the main settings as a feature. Of course, this is only a matter of detail.

For me, it's forcing you to get it out of the library with another layer of code from the beginning.

You can try it out, compare performance with Fleck and decide which is better for your simple project.

Advantage:

    • Simple

    • No dependency

    • Complete documentation

Disadvantages:

    • A little clumsy, more complicated than the fleck structure.

    • No fallback.

Xsockets

http://xsockets.net/

The library looks promising. I tried it and spent a lot of time working with it over other libraries (even for testing, etc.). But unfortunately I have no luck, and any mistakes I have taken into account in this library are all wrong, bad documents that are inconsistent with the code. Is it because the code or the document expires? It is not easy to install and run, in fact, the use of this library sample I difficult to build and run. Xsocket more shows us what the MVC framework looks like. I tried to run it inside the ASP, MVC and WinService, and unfortunately none of them could work.

I really wanted to use this library, but in the end I gave up to support a better library (read more). Seriously why using this library is difficult, even for a simple project. You can predict more problems when it is used in the project, I strongly recommend to avoid this project.

public static class xsocketsbootstrap{private static Ixbaseservercontainer wss;        public static void Start () {WSS = XSockets.Plugin.Framework.Composable.GetExport (); Wss.    Startservers (); }}

<p>advantages:</p><ul><li>seems powerful</li><li>should have  good JavaScript integration</li></ul><p>Disadvantages:</p><ul> <li>Complicated and hard</li><li>Complicated to configure and  run inside of webforms, mvc and winservice</li><li>differences  between code and documentation</li><li>outdated documentation and  Examples</li></ul></li><li>Superwebsocket

http://superwebsocket.codeplex.com/

Last but not least, superwebsocket. I have a little doubt about this (if I remember correctly, this is just a package I found through the NuGet website, but not a usable package). It seems a little complicated, but in fact it is very simple. Examples of documentation support help you step-by-step from the simplest WebSocket server to a complex WebSocket server with command requests, JSON, multi-server instances,. config file configurations, or more.

This library may not contain the cool features of all the other libraries, but it doesn't matter, because it's highly configurable and you can easily make it do what you want. It can be run as a console application or as a Windows service in ASP. In the literature, it is recommended to run the server as a system service. From my experience, it is recommended that you do not run it in a Web application because the solution is slow (very bad performance, about 50 times times slower than the console application). On the other hand, standalone server applications need to run files ending with. exe, which is not part of the library, but is part of the SuperSocket project (Superwebsocket is based on this project). This allows you to have a little bit of finesse to turn on the server in a debugging session, or to fully enable debugging. While you are running the server as an application, although this is not part of the solution, you also need to make sure that the server uses the latest version of the components from other projects.

In return, you get a well-known solution for flexible websocket.

It's still open source so you can change it as needed.

On the other hand, you might consider this server lacks JavaScript client as its disadvantage (but it has a C # client). This server also has third-party dependencies.

After working with this library for a few months I didn't find any major problems.

Disadvantages and Advantages:

    • No standby communication

    • Depend on

    • Elegant features and highly configurable

    • It's a great example.

    • Examples of documents with recommended settings

    • Can be run as Windows Service and ASP and console applications

    • Good performance

Summarize

For complex solutions/projects I recommend using Superwebsocket because it is a stable and highly configurable library. For simple and fast-developing projects I would choose Fleck, but if there is a way to use the latest Windows server as a test and production machine, I will give up using both and choose Signalr.

This address: http://www.oschina.net/translate/websocket-libraries-comparison-2

Original address: Http://www.codeproject.com/Articles/733297/WebSocket-libraries-comparison-2

Reference Address: http://www.open-open.com/lib/view/open1394254398458.html

. NET WebSocket Development Package Comparison

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.