本文介绍了socketio上的flashsocket和nodejs不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我没有看到我所看到的是什么如果有人可以帮忙的话,我会做错的。

在服务器端

  var app = express.createServer(),
io = require('socket.io')。listen(app,{
flashPolicyServer:true,
运输:['flashsocket','htmlfile','xhr-polling','jsonp-polling']
});
app.listen(80);

在客户端

  ... 
...
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正在监听并响应:

pre $ c $< cross-domain-policy>
< allow-access-from domain =*to-ports =*/>
< / cross-domain-policy>

在服务器日志中,只能得到:

 调试静态内容/socket.io.js 
debug - 客户端授权
info - 握手授权14328044138726156
调试 - 设置请求GET / socket .io / 1 / xhr-polling / 14328044138726156?t = 1333755740295
调试 - 设置轮询超时
调试 - 客户端授权
调试 - 清除轮询超时
调试 - xhr-polling写1 ::
调试 - 为客户端设置关闭超时14328044138726156
调试 - 设置请求GET /socket.io/1/xhr-polling/14328044138726156?t=1333755740299
调试 - 设置轮询超时
debug - 清除轮询超时
debug - xhr-polling写入5 ::: {name:echo,args:[transport type:xhr-polling; and socket.id: 14328044138726156]}
debug - 为客户端设置关闭超时14328044138726156
debug - 放弃传输
debug - 为客户端清除关闭超时14328044138726156
调试 - 设置请求GET /套接字。 io / 1 / xhr-polling / 14328044138726156?t = 1333755740303
调试 - 设置轮询超时
调试 - 丢弃传输
调试 - 清除客户端的关闭超时14328044138726156
调试 - 清除轮询timeout
debug -xhr-polling写入8 ::
debug - 为客户端设置关闭超时14328044138726156`

感谢您的帮助

解决方案

b $ b

感谢XHR,您引导我进行更多的分析和测试,以便自己找到。

它可以工作,但与预期不同:
在浏览器中启用websocket时,不能使用flashsocket。

所以,即使您使用传输设置服务器:[' flashsocket','htmlfile','xhr-polling','jsonp-polling'] 你的谷歌浏览器永远不会使用flashsocket,因为它启用了websocket,并且回退到xhr-polling。
但没有启用websocket的Internet Explorer将使用flashsocket。

我没有必要在没有websocket的情况下设置socket.io,所以这种行为适用于我
$ b

此外,我认为这种行为是不错的,因为它可以防止在你不需要的时候加载重的.swf文件。




I'm trying to get flashsocket working with socket.io but it does not, always going in xhr-polling fallback.

I don't see what I'm doing wrong, if anybody can help.

On server side :

var app = express.createServer(),
io = require('socket.io').listen(app, {
    flashPolicyServer: true,
    transports: ['flashsocket', 'htmlfile', 'xhr-polling', 'jsonp-polling']
});
app.listen(80);

On client side :

...
<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);
                });
            });

After that I checked that my browser chrome has flash enabled.I also checked that port 843 and 10843 are listening and responding :

<cross-domain-policy>
    <allow-access-from domain="*" to-ports="*"/>
</cross-domain-policy>

On the server log, only get :

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`

Thanks for you help

解决方案

In fact, it works !

Thanks to XHR, you lead me to more analyze and test so I could found by myself.

It works, but different as expected :When websocket is enabled on a browser, you cannot use flashsocket instead.

So even if you setup the server with : transports: ['flashsocket', 'htmlfile', 'xhr-polling', 'jsonp-polling'] your google chrome will never use flashsocket because it has websocket enabled and it falls back to xhr-polling.But Internet explorer which doesn't have websocket enabled will use flashsocket.

And I have no need to setup socket.io without websocket so this behavior works for me.

Moreover I think this behavior is nice because it prevents loading heavy .swf files when you don't need them.

Jerome.

这篇关于socketio上的flashsocket和nodejs不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 08:09