2012-01-02 53 views
1

我在端口3030上运行快速Web应用程序,但它通过http-proxy代理。该网站以这种方式正常工作,但socket.io不会连接。它收到的东西作为我的控制台显示:NodeJS,http-proxy,socket.io

debug - served static content /socket.io.js 
debug - client authorized 
info - handshake authorized 11319742841450363586 
debug - setting request GET /socket.io/1/websocket/11319742841450363586 
debug - set heartbeat interval for client 11319742841450363586 
debug - client authorized for 
debug - websocket writing 1:: 

app.js

app.listen(3030) 

io = require('socket.io') 
socket = io.listen(app) 

socket.on('connection', function(client) { 
    console.log('new connection') 
}) 

chat.js

$(function() { 
    console.log('connecting to chat...') 
    var socket = io.connect('http://mydomain.com:80') 

    socket.on('connected',function(){ 
    console.log('connected') 
    }) 
}) 

然而,无论是有史以来的console.log语句显示在客户端或服务器端。我究竟做错了什么?

编辑 - 添加HTTP代理代码

var httpProxy = require('http-proxy') 
    , proxyTable = { 
     router: { 
     'lou.mydomain.com': '127.0.0.1:3030' 
     , 'foe.mydomain.com': '127.0.0.1:3000' 
     // and some others 
     } 
    } 
    , proxyServer = httpProxy.createServer(proxyTable); 

proxyServer.listen(80); 
+0

你应该粘贴您的HTTP代理配置 – 2012-01-02 10:01:17

+0

@xsace的代码 - 我编辑的职位,包括HTTP代理脚本 – 2012-01-02 10:07:35

+0

我遇到了同样的问题。你有没有想过它? – 2012-11-01 05:40:18

回答

1

据我所知,节点HTTP代理不使用WebSockets与节点工作> 0.6.x,因为一个错误的(这是几个星期前)。他们说他们正在修复,所以他们可能还没有解决这个问题。如果你不能这样做,请尝试bouncy

+2

对于任何想知道的人来说,alessioalex提到的问题应该已经在socket.io 0.8.0中解决了:https://github.com/nodejitsu/node -http-proxy/issues/161 – 2012-02-14 21:12:35

0

难道你不应该问地址127.0.0.1:3030上的socket.io?还连接到mydomain.com:3030。

如果我理解正确,你在3030端口上运行express应用程序,这样你就需要在那里连接到客户端JS。

$(function() { 
    console.log('connecting to chat...') 
    var socket = io.connect('http://mydomain.com:3030'); 

    socket.on('connected',function(){ 
    console.log('connected') 
    }); 
}); 

我猜...

+0

他代理端口80,所以他的代码是正确的。 – alessioalex 2012-01-02 13:07:52