我试图让 flashsocket 与 socket.io 一起工作,但它没有,总是在 xhr-polling 后备中。
如果有人可以提供帮助,我看不出我做错了什么。
在服务器端:
var app = express.createServer(),
io = require('socket.io').listen(app, {
flashPolicyServer: true,
transports: ['flashsocket', 'htmlfile', 'xhr-polling', 'jsonp-polling']
});
app.listen(80);
在客户端:
...
<script src="/socket.io/socket.io.js"></script>
...
socket = io.connect();
socket.on('connect', function(evt) {
console.log(socket.socket.transport.name);
onOpen(timeDifference(new Date(), earlierDate), socket.socket.transport.name);
earlierDate = new Date();
socket.on('disconnect', function(evt) {
onClose(evt);
});
socket.on('echo', function(msg) {
onEcho(msg);
});
socket.on('error', function(evt) {
onError(evt);
});
});
之后,我检查了我的浏览器 chrome 是否启用了 flash。我还检查了端口 843 和 10843 是否正在侦听和响应:
<cross-domain-policy>
<allow-access-from domain="*" to-ports="*"/>
</cross-domain-policy>
在服务器日志上,仅获取:
debug - served static content /socket.io.js
debug - client authorized
info - handshake authorized 14328044138726156
debug - setting request GET /socket.io/1/xhr-polling/14328044138726156?t=1333755740295
debug - setting poll timeout
debug - client authorized for
debug - clearing poll timeout
debug - xhr-polling writing 1::
debug - set close timeout for client 14328044138726156
debug - setting request GET /socket.io/1/xhr-polling/14328044138726156?t=1333755740299
debug - setting poll timeout
debug - clearing poll timeout
debug - xhr-polling writing 5:::{"name":"echo","args":["transport type : xhr-polling; and socket.id : 14328044138726156"]}
debug - set close timeout for client 14328044138726156
debug - discarding transport
debug - cleared close timeout for client 14328044138726156
debug - setting request GET /socket.io/1/xhr-polling/14328044138726156?t=1333755740303
debug - setting poll timeout
debug - discarding transport
debug - cleared close timeout for client 14328044138726156
debug - clearing poll timeout
debug - xhr-polling writing 8::
debug - set close timeout for client 14328044138726156`
谢谢你的帮助