node.js의 서버 측 논리로 html5에서 게임을하려고하는데 raw websockets (Socket.IO가 아닌 이진 데이터가 필요함)을 사용합니다. 여러 개의 "객실"을 보유하고 있으므로 여러 개의 웹 소켓 서버에 모두 별도의 URL이 있습니다. 현재, 각 웹 서버를 특정 포트에 연결 한 다음 URL을 기반으로 올바른 포트로 업그레이드 요청 (완전히 작동하지 않는 방법)을 프록시 처리하는 방법을 찾았습니다.Nodejs : 포트 프록시가없는 URL을 기반으로 한 websocket 라우팅
내 컴퓨터에서 작동합니다. 문제는 내가 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".
내 질문 : 여기
내 코드의 꽤 정리 버전은 특정 포트를 듣고없이 웹 소켓 서버를 열려면 어떻게 든 가능하며, 수동으로 내가 돈 때문에 그들에게 소켓을 연결하는 기본 http 포트가 아닌 다른 포트를 열 필요가 있습니까? 소켓을 알아 .IO는 어떻게 든 그것을한다. 어쩌면 http 서버의 업그레이드 이벤트를 듣고 올바른 웹 소켓 서버에 소켓을 전달하는 방법이 있을까요?나는 서버 쪽 물건에 매우 익숙하다. 그래서 여분의 정보가 여기 저기 환영받을 것이다.