Node.js Hosting w/Multiple Ports, or wrong practice?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 01:11:10

问题


I'm trying to figure out the best workflow for producing an app I can have hosted on one of the various public Node environments. The sticking point seems to be that my app opens two ports: one for HTTP and another for WebSockets.

Here's the code which executes great on my own system, but runs into EADDRINUSE errors on hosted services. (NOTE: this is regardless of changes in port number)

CODE: http://pastebin.com/zjJKbj2U

QUESTION: Am I wrong in my approach of searching for a Node service that provides this ability, or should I be going about this in a different way?


回答1:


Do you have a specific reason you think you need a different port for HTTP and web sockets? They are designed to work fine using the same port, and as you are seeing, things are much easier if you just use them that way. Your app can access both regular web resources as well as opening a web socket connection to the server at the same time over a single port. There's an example of using express for your web site and ws for websockets on the same port here.



来源:https://stackoverflow.com/questions/24639912/node-js-hosting-w-multiple-ports-or-wrong-practice

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