【发布时间】:2013-03-11 21:03:31
【问题描述】:
我在这个论坛上看到了一些关于 Socket.IO 和 node.js 的帖子。但仍无法以最佳方式工作。
端口 80 和端口 8080 被我的网络服务器用于不同的应用程序。所以在 App.js 和我的套接字连接中,我添加了端口 8081 而不是 8080。
我收到 websocket 连接无效消息。大约 10 秒后,它创建了 websocket,我可以很好地使用它。
但是 10 秒太长了。任何想法如何解决这个问题?
script.js:
<script>
var socket = io.connect('http://domainname.nl:8081');
socket.on('connect', function(){
socket.emit('adduser', "<?php echo $user->first_name; ?>");
});
app.js
var app = require('express').createServer()
var io = require('socket.io').listen(8081);
app.listen(8081);
// routing
app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.html');
});
更新:
当我改变它时。我仍然有问题。套接字工作,但需要 10 秒才能连接
info - socket.io started
debug - served static /socket.io.js
debug - client authorized
info - handshake authorized 15619940591959058675
debug - setting request GET /socket.io/1/websocket/15619940591959058675
debug - set heartbeat interval for client 15619940591959058675
warn - websocket connection invalid
info - transport end
debug - set close timeout for client 15619940591959058675
debug - cleared close timeout for client 15619940591959058675
debug - cleared heartbeat interval for client 15619940591959058675
debug - client authorized for
debug - setting request GET /socket.io/1/xhr-polling/15619940591959058675?t=1345479037596
debug - setting poll timeout
debug - clearing poll timeout
【问题讨论】:
-
我今天在我的应用程序中注意到了同样的事情。它直接在端口 16667 上正确运行,但在通过代理设置运行时会出现此问题,该代理设置将端口 80 流量从那里的域重定向。