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]}
javascript android websocket
Ben mircircoft
source share