How to browserify a Node.js WebSocket server?

谁说我不能喝 提交于 2019-12-08 09:09:33

问题


Using examples from node-chromify I managed to run a Node.js Http server on a client side - inside a Chrome browser.

Then I tried to do exactly the same with a WebSocket server. Unfortunately I failed. I think I tried most of the popular WebSocket libraries (npm modules) from Github.

While they work fine in configurations:

(a) both a WebSocket server and a WebSocket client are started from a Node command line
(b) the server runs from the command line and the client is included as a JavaScript in a html page (runs on a client side)

the scenario

(c) both the WebSocket server and the client running in a browser

is still unattainable for me so far.

During my attempts I tried the same approach by calling a command:

browserify server-ws.js -o bundle-server-ws.js

but when I included the generated bundle file into a html page I got always some critical errors regarding missing object definitions, etc. In other words the above command seems not to bundle everything as the server code would expect during a runtime.

Should I use different switches/options during calling browserify?

Maybe it is not possible for browserify at all? For a client OK but with a server not...

I realize that migrating WebSocket stuff to the client side is much more complicated process than a regular npm module.

browserify v. 2.36.1

Node 0.10.22

来源:https://stackoverflow.com/questions/20538184/how-to-browserify-a-node-js-websocket-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!