问题
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