WebSocket的在Android的股票浏览器或支持的呢? [英] WebSocket supported in Android Stock Browser or not?

查看:335
本文介绍了WebSocket的在Android的股票浏览器或支持的呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 https://github.com/einaros/ws

服务器:

  VAR WebSocketServer =要求(WS)服务器,WSS =新WebSocketServer({端口:8004})。

wss.on('连接',功能(S){
    s.on('消息',函数(_){执行console.log('收到的:'+ _);});
});
 

客户端:

 变种S =新的WebSocket(WS://mysite.com:8004);
// Android的默认浏览器模具此处< ---------------?
s.onopen =功能(){
    $('身体')的CSS({'背景':'绿色'});
    s.send('喜');
    };
 

我要问为什么的Andr​​oid默认浏览器不打开连接?

我访问的默认Android浏览器www.websocket.org/echo.html和它说的这个浏览器支持WebSocket的。那有什么问题呢?

这个简单的code适用于iPhone Safari浏览器,Chrome浏览器的窗口,Android手机铬没有问题。

在Android的默认浏览器,我也可以console.dir(window.WebSocket);它显示了WebSocket的对象没有不同于其他浏览器。

如果有人知道这是为什么,请告知。

感谢


更新

 如果(window.WebSocket&安培;!&安培; window.MozWebSocket){
    window.WebSocket = window.MozWebSocket;
    警报('MozWebSocket');
}
否则,如果(!window.WebSocket){
    警报(的WebSocket不支持该浏览器);
}
其他{
    警报('WTF!?+ window.WebSocket);
}
 

这给了我一个控制台日志:

  WTF!?功能的WebSocket(){[本地code]}
 

解决方案

Android的股票浏览器不,事实上,支持WebSocket的。

有些工作显然是在preparation做了添加支持,所以在浏览器中的API是存在的,即你可以创建一个WebSocket的对象。这只是这实际上并没有做幕后事情。

这会导致一个简单的功能支持检查,这只是尝试创建Socket对象,表现出的WebSocket支持。检查的readyState为创建WebSocket的对象,而不是,你会看到,这个从来没有从0的变化。

与Android 4.4开始,没有现货的浏览器了。 Web视图组件已经切换到Chrome浏览器Android版 - 这不支持WebSocket的

using https://github.com/einaros/ws

Server:

var WebSocketServer=require('ws').Server,wss=new WebSocketServer({port:8004});

wss.on('connection',function(s) {
    s.on('message',function(_){console.log('received: '+_);});
});

Client:

var s=new WebSocket('ws://mysite.com:8004');
//android default browser dies here <---------------?       
s.onopen=function(){
    $('body').css({'background':'green'});
    s.send('hi');
    };

I have to ask why android default browser does not open the connection?

I visit www.websocket.org/echo.html on the default android browser and it says This browser supports websocket. so what is the problem?

This simple code works on iphone safari, windows chrome, android mobile chrome no problem.

On android default browser I can also console.dir(window.WebSocket); and it shows the WebSocket Object no differently than other browsers.

If someone knows why, please tell.

Thanks


UPDATE

if (!window.WebSocket && window.MozWebSocket) {
    window.WebSocket = window.MozWebSocket;
    alert('MozWebSocket');
}
else if (!window.WebSocket) {
    alert("WebSocket not supported by this browser");
}
else{
    alert('wtf!? '+window.WebSocket);
}

This gives me a console log of:

wtf!? function WebSocket(){[native code]}

解决方案

The Android stock browser does not, in fact, support WebSocket.

Some work was apparently done in preparation for adding support, so the API in the browser is there, i.e. you can create a WebSocket object. It's just that this doesn't actually do anything behind the scenes.

This results in a simple feature support check, which just attempts to create the socket object, showing WebSocket support. Check the readyState for a created WebSocket object instead, and you'll see that this never changes from "0".

Starting with Android 4.4, there is no stock browser anymore. The Web view component has been switched to Chrome for Android - and this does support WebSocket.

这篇关于WebSocket的在Android的股票浏览器或支持的呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆