【发布时间】:2020-04-10 05:02:28
【问题描述】:
我正在尝试让 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`
感谢您的帮助
【问题讨论】:
-
您是否确认客户端正在请求并正确接收 SWF 文件?
-
谢谢你的问题:是的,我已经检查过了:但客户甚至没有请求这个文件。我还验证了 .swf 可以访问:是的。
-
为了更清楚,我检查了:localhost/socket.io/WebSocketMain.swf:我在屏幕上有一个很好的“欢迎来到 socket.io。”
-
如果我检查localhost/socket.io/flashsocket/WebSocketMain.swf,我会得到“不支持协议版本”。在屏幕和 nodejs 服务器上显示“不支持客户端协议版本”。在之前的检查(localhost/socket.io/WebSocketMain.swf)中,我进入了服务器:“unhandled socket.io url”
-
您说“客户端甚至没有请求此文件”。这听起来像问题,很难在页面上没有 Flash 对象的情况下制作 Flash 套接字。你可能需要设置
WEB_SOCKET_SWF_LOCATION,见socket.io/#faq