Could Node.js run client side in Chrome with its n

2020-05-18 21:16发布

Google Chrome's native client is soon to be released. http://blog.chromium.org/2011/02/native-client-getting-ready-for-takeoff.html Would 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?

4条回答
霸刀☆藐视天下
2楼-- · 2020-05-18 21:32

Nowadays there are several solutions that allow you to run some Node modules in chrome. Have a look on these links:

查看更多
疯言疯语
3楼-- · 2020-05-18 21:39

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.

From a comment by Brad Chen on Jan 28, 2014, in the thread "Has anyone tried porting Blink and V8 to 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.

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.

查看更多
霸刀☆藐视天下
4楼-- · 2020-05-18 21:52

node.js is not pure Javascript code. There are parts of it written in C++ so this is unlikely.

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.

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.

查看更多
▲ chillily
5楼-- · 2020-05-18 21:56

You can't run Node.js in a browser.

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 RTMFP which 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 recently that does exactly that.

查看更多
登录 后发表回答