Node.js主机瓦特/多端口,或错误的做法? [英] Node.js Hosting w/Multiple Ports, or wrong practice?

查看:183
本文介绍了Node.js主机瓦特/多端口,或错误的做法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出制作我可以在各种公共节点环境之一托管的应用程序的最佳工作流程。症结似乎是我的应用程序打开两个端口:一个用于HTTP,另一个的WebSockets

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.

下面是该我自己的系统上执行很大的代码,但跑入EADDRINUSE托管服务错误。 (注意:这是端口号的改变,无论)

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?

推荐答案

你有你认为你需要一个不同的端口用于HTTP具体原因和网络套接字?它们被设计成可以使用相同的端口正常工作,而且正如您所看到的,如果您只是以这种方式使用它们,事情会变得更加容易。您的应用程序既可以访问常规Web资源,也可以通过单个端口同时打开与服务器的Web套接字连接。有使用快递为您的网站和WS为的例子在同一个端口上的websockets在这里

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.

这篇关于Node.js主机瓦特/多端口,或错误的做法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆