我試圖讓flashsocket與socket.io一起工作,但它並不總是在xhr-polling後備中進行。socketio上的flashsocket和nodejs不能正常工作
我沒有看到我做錯了什麼,如果有人可以幫助。
在服務器端:
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瀏覽器已經啓用閃光燈。 我還檢查端口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文件? – 2012-04-09 19:00:49
謝謝你的問題:是的,我檢查過:但客戶端甚至沒有要求這個文件。我還驗證了.swf可以被訪問:它是。 – jerome 2012-04-10 14:30:22
更清楚我檢查:http://localhost/socket.io/WebSocketMain.swf:我在屏幕上有一個不錯的「歡迎來到socket.io」。 – jerome 2012-04-10 14:46:08