Node.Js + Socket.IO vs SignalR vs C# WebSocket 服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9537641/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Node.Js + Socket.IO vs SignalR vs C# WebSocket Server
提问by Jon
I currently have a TCP server application written in .Net that receives and submits messages to clients. I am looking at building a web application so need the communication layer.
我目前有一个用 .Net 编写的 TCP 服务器应用程序,它接收并向客户端提交消息。我正在考虑构建一个 Web 应用程序,因此需要通信层。
I have built a Node.JS + Socket.IO app which connects to my TCP server and then pushes communication to the web application and all works fine.
我已经构建了一个 Node.JS + Socket.IO 应用程序,它连接到我的 TCP 服务器,然后将通信推送到 Web 应用程序,并且一切正常。
I have just read about SignalR as an alternative to keep it in the .Net stack.
我刚刚阅读了 SignalR 作为将其保留在 .Net 堆栈中的替代方法。
However I have also found that I could write a C# Websocket Server, a basic demo here
但是我也发现我可以写一个 C# Websocket 服务器,这里是一个基本的演示
I assume that this basic server is what SignalR is but obviously with a lot more functionality in it?
我认为这个基本服务器就是 SignalR,但显然它具有更多功能?
What I'm trying to decide is do I just append my current TCP application with a Websocket server or do I go down a separate SignalR or Node.js route? Out of interest how does a SignalR application run, is it as a Windows service, console app or IIS service?
我要决定的是,我是将当前的 TCP 应用程序附加到 Websocket 服务器,还是使用单独的 SignalR 或 Node.js 路由?出于兴趣,SignalR 应用程序如何运行,它是作为 Windows 服务、控制台应用程序还是 IIS 服务?
采纳答案by Damian Edwards
SignalR is like Socket.IO in that it supports transport negotiation/fallback. It is a framework and not a server, so you need to host it on a server of some sort. We have hosts for ASP.NET, OWIN (e.g. Kayak) and self-host, so you can run it in your own process easily, e.g. a Windows service.
SignalR 类似于 Socket.IO,因为它支持传输协商/回退。它是一个框架而不是服务器,因此您需要将它托管在某种服务器上。我们有用于 ASP.NET、OWIN(例如 Kayak)和自托管的主机,因此您可以轻松地在您自己的进程中运行它,例如 Windows 服务。
SignalR has supported clients for browsers (JS), .NET, Windows Phone 7 and Silverlight. There are also contributed clients for things like iOS, Mono Touch, etc.
SignalR 支持浏览器 (JS)、.NET、Windows Phone 7 和 Silverlight 的客户端。也有为 iOS、Mono Touch 等提供的客户端。
SignalR will give you a much higher level API than raw sockets which is its big advantage, allowing you to do things like "RPC" from server to clients in a broadcast (or targeted) fashion.
SignalR 将为您提供比原始套接字更高级别的 API,这是它的一大优势,允许您以广播(或有针对性)的方式从服务器到客户端执行“RPC”等操作。
回答by Zuuum
Developing a scalable / thread safe TCP server may not be an easy task. On the other hand, there are very nice resources on the internet in order to start your own. For example, if you are just looking for some nice open source WebSocket projects, my advice would be ;
开发可扩展/线程安全的 TCP 服务器可能不是一件容易的事。另一方面,互联网上有非常好的资源可以开始你自己的。例如,如果您只是在寻找一些不错的开源 WebSocket 项目,我的建议是;
Alchemy Project: Open Source C# WebSocket Library
Alchemy 项目:开源 C# WebSocket 库
Fleck Project: Open Source C# WebSocket Library
Fleck 项目:开源 C# WebSocket 库
SignalR could be nice but it needs Windows Server 8 / IIS 8 in order to provide WebSocket feature.
SignalR 可能不错,但它需要 Windows Server 8 / IIS 8 才能提供 WebSocket 功能。
On the commercial product side, especially considering the websocket feature is not available on all the browsers, i recommend PokeIn WebSocket and reverse Ajax Library. Starting from version 2.0 it has built-in WebSocket server. Details available from here
在商业产品方面,特别是考虑到并非所有浏览器都提供 websocket 功能,我推荐 PokeIn WebSocket 和反向 Ajax 库。从版本 2.0 开始,它具有内置的 WebSocket 服务器。详情可从这里获得
回答by cchamberlain
Other implications
其他影响
I've used both technologies and work on both sides of the .NET / node stacks.
我使用过这两种技术,并在 .NET / 节点堆栈的两端工作。
- Although I prefer the node side these days, if you only work in .NET, SignalR is the obvious choice. Conversely, if you build all your projects in node I would go with socket.io or sockjs. If your scope is narrow enough that you don't need to worry about fallbacks and that sort of thing, I'd recommend checking out wsmodule since its simpler and lighter on your dependencies. In the past, socket.io has been a pain on Windows due to install issues with node-gyp failing to install native dependencies (node-gyprequires many configuration steps that vary wildly depending on which version of Windows you have but is required for C++ native built modules). UPDATEThis Windows bit is not so much relevant anymore thanks to windows-build-tools.
- If you have a load balancer and are planning on running SignalR, you are going to need to setup SQL or Redis as a backplane to bypass the load balancer. You will have similar issues to deal with on the socket.io side and there are [multiple supported methods][1] (1 of which is redis also).
- 虽然我现在更喜欢节点方面,但如果你只在 .NET 中工作,那么 SignalR 是显而易见的选择。相反,如果您在 node 中构建所有项目,我会使用 socket.io 或sockjs。如果您的范围足够窄,您无需担心回退之类的事情,我建议您查看ws模块,因为它对您的依赖项更简单、更轻松。过去,由于 node-gyp 无法安装本机依赖项的安装问题,socket.io 在 Windows 上一直很痛苦(node-gyp需要许多配置步骤,这些步骤因您拥有的 Windows 版本而异,但 C++ 需要这些步骤本机构建的模块)。更新这个 Windows 位不再那么重要了windows-build-tools。
- 如果您有负载均衡器并计划运行 SignalR,您将需要设置 SQL 或 Redis 作为背板来绕过负载均衡器。您将在 socket.io 端处理类似的问题,并且有 [多种支持的方法][1](其中 1 个也是 redis)。
Update - removed jquery info since it is no longer applicable
更新 - 删除了 jquery 信息,因为它不再适用

