Is WebSocket supported in Android Stock Browser or not?

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 the default browser for Android does not open the connection?

I visit www.websocket.org/echo.html in the default browser and says: This browser supports websocket. , what is the problem?

This simple code works on iphone safari, windows chrome, android mobile chrome without any problems.

In the default browser for Android, I can also use console.dir (window.WebSocket); and it shows a WebSocket object just like other browsers.

If someone knows why, please let me know.

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:

 wtf!? function WebSocket(){[native code]} 
+8
javascript android websocket
source share
1 answer

The Android Android browser does not support WebSocket.

Some of the work, apparently, was done in preparation for adding support, so there is an API in the browser, i.e. You can create a WebSocket object. It just doesn't do anything backstage.

This results in a simple function support check, which simply tries to create a socket object, showing support for WebSocket. Instead, check readyState for the created WebSocket object, and you will see that it never changes from "0".

Starting with Android 4.4, the stock browser is no longer there. The web browsing component has been switched to Chrome for Android, and it supports WebSocket.

+13
source share

All Articles