Nodejs:基于URL的websocket路由,无需端口代理

我正在尝试在html5中使用node.js中的服务器端逻辑进行游戏,并使用原始websockets(而不是Socket.IO,我需要二进制数据)。 我希望有多个“房间”,因此多个websocket服务器,都有单独的URL。 目前,我只find了一种方法,让每个websocket服务器连接到一个特定的端口,然后代理升级请求(不完全知道它是如何工作的)基于URL的正确的端口。

它在我的电脑上运行。 问题是,当我尝试将其提交给PaaS提供程序(AppFog)时,代码失败,因为它们不允许打开提供的http端口以外的任何端口。

这是一个相当清晰的我的代码版本:

//start web server (basic static express server) on 8080 // ... //start game server and listen to port 9000 // I use the ws module for websockets // I plan to have a couple of these "game servers" // ... //open the proxy server. var httpProxy= require('http-proxy'); var webProxyServer = httpProxy.createServer(function (req, res, proxy){ // I need http requests to be redirected to the "game servers" if(req.url.substring(0, "/room1".length) === "/room1") // if starts with "/room1" proxy.proxyRequest(req, res, { host: 'localhost', port: 9000 }); else proxy.proxyRequest(req, res, { host: 'localhost', port: 8080 }); } webProxyServer.on('upgrade', function (req, socket, head) { //redirecting logic goes here if(req.url=="/room1/"){ webProxyServer.proxy.proxyWebSocketRequest(req, socket, head, { host: 'localhost', port: 9000 }) } }); webProxyServer.listen(8000); //the "outside port". 

我的问题是:是否有可能打开websocket服务器,而不听任何特定的端口,并手动将套接字连接到他们,所以我不需要打开除基本http端口以外的任何端口? 我知道Socket.IO不知何故。 也许有一种方法来监听http服务器的升级事件,并将套接字传递给正确的websocket服务器?

我很新的服务器端的东西,所以额外的信息在这里和那里会受到欢迎。

不幸的是,Appfog不支持websocket。

function路线图页面 – 页面底部:显示websockets即将推出(即他们不支持它)。