javascript Node.js 能否在 Chrome 中使用其本机客户端运行客户端(即将发布)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5081191/
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
Could Node.js run client side in Chrome with its native client (to be released soon)
提问by Sycren
Google Chrome's native client is soon to be released. http://blog.chromium.org/2011/02/native-client-getting-ready-for-takeoff.htmlWould this allow node.js to be run within the browser enabling distributed applications to communicate with each other without having to go through the server?
谷歌浏览器的原生客户端即将发布。http://blog.chromium.org/2011/02/native-client-getting-ready-for-takeoff.html这是否允许 node.js 在浏览器中运行,使分布式应用程序无需相互通信即可通过服务器?
采纳答案by Michael Dillon
node.js is not pure Javascript code. There are parts of it written in C++ so this is unlikely.
node.js 不是纯 Javascript 代码。它的一部分是用 C++ 编写的,所以这不太可能。
There are a couple of possibilities for distributed communication. One is to use the Websockets api in the browser to communicate with other browsers. The other one is to run node.js as a separate server process on the same machine as the browser.
分布式通信有几种可能性。一种是在浏览器中使用Websockets api与其他浏览器进行通信。另一种是在浏览器所在的同一台机器上将 node.js 作为单独的服务器进程运行。
This second is a better choice for building a distributed application because it reduces dependence on the browser. Version 0.5.0pre of node.js now builds OK on Cygwin and it is possible to bundle up the essential components of Cygwin as a standalone binary to distribute to Windows clients. Older versions of node.js used to be distributed this way.
这第二个是构建分布式应用程序的更好选择,因为它减少了对浏览器的依赖。node.js 的 0.5.0pre 版本现在可以在 Cygwin 上构建,并且可以将 Cygwin 的基本组件捆绑为独立的二进制文件以分发给 Windows 客户端。旧版本的 node.js 曾经以这种方式分发。
回答by Bertrand
Nowadays there are several solutions that allow you to run some Node modules in chrome. Have a look on these links:
现在有几种解决方案可以让你在 chrome 中运行一些 Node 模块。看看这些链接:
node-webkitis an app runtime based on Chromium and node.js.
Node-chromify, Node.js in Chrome.
Screen castfrom google about NodeJS in Chrome packaged apps.
node-webkit是一个基于 Chromium 和 node.js 的应用运行时。
Node-chromify,Chrome 中的 Node.js。
谷歌关于 Chrome 打包应用程序中的 NodeJS 的屏幕截图。
回答by thinkmassive
As of today, Node.js will not run in NaCl, however it may be possible eventually. Node uses the V8 JavaScript engine to execute code. Currently there is no reliable port of the V8 engine that will run within NaCl.
截至今天,Node.js 不会在 NaCl 中运行,但最终可能会实现。Node 使用 V8 JavaScript 引擎来执行代码。目前没有可靠的 V8 引擎端口可以在 NaCl 中运行。
From a comment by Brad Chen on Jan 28, 2014, in the thread "Has anyone tried porting Blink and V8 to Native Client?":
来自 Brad Chen 于 2014 年 1 月 28 日的评论,在主题“是否有人尝试将 Blink 和 V8 移植到 Native Client?”中:
V8 has been ported to Native Client, although the port used an unsavory trick of having V8 generate ARM instructions and then use a portable ARM interpreter to avoid the need to port V8 code generators to NaCl. You should be able to observe this by checking out V8 source and following the standard build/test instructions using targets nacl_ia32 or nacl_x64.
V8 已被移植到 Native Client,尽管该移植使用了一个令人讨厌的技巧,让 V8 生成 ARM 指令,然后使用便携式 ARM 解释器来避免将 V8 代码生成器移植到 NaCl 的需要。您应该能够通过查看 V8 源代码并按照使用目标 nacl_ia32 或 nacl_x64 的标准构建/测试说明来观察这一点。
https://groups.google.com/d/msg/native-client-discuss/Xw5yCe3Ubwc/fgm6M092DXwJ
https://groups.google.com/d/msg/native-client-discuss/Xw5yCe3Ubwc/fgm6M092DXwJ
Considering that V8 has already been able to run under NaCl, albeit with an unreliable hack, it's reasonable to assume that Node might eventually be able to run in NaCl. I realize your question is now three years old but figured I'd provide an updated answer since running native code (even OpenGL code) in the browser is now a reality.
考虑到 V8 已经能够在 NaCl 下运行,尽管存在不可靠的 hack,可以合理地假设 Node 最终可能能够在 NaCl 中运行。我意识到您的问题现在已经三年了,但我想我会提供更新的答案,因为在浏览器中运行本机代码(甚至 OpenGL 代码)现在已成为现实。
回答by HoLyVieR
You can't run Node.js in a browser.
你不能在浏览器中运行 Node.js。
However, if you want to do P2P connection, it's possible if the browser has the latest version of Flash (Flash 10) installed. In the latest version, they introduced RTMFPwhich let's you do P2P connection without passing through a server. If you want to use it in Javascript, you can make a bridge or you can take a look at a project I started recentlythat does exactly that.
但是,如果您想进行 P2P 连接,则浏览器安装最新版本的 Flash (Flash 10) 是可能的。在最新版本中,他们引入了RTMFP,让您无需通过服务器即可进行 P2P 连接。如果你想在 Javascript 中使用它,你可以做一个桥梁,或者你可以看看我最近开始的一个项目,它就是这样做的。

