android browser and socket io

Go To StackoverFlow.com

7

I having trouble getting socket io to send a response on connect for the android browser. I logged the parameters and they are appearing server side, it just seems like that the client side doesn't properly connnect. I disabled jsonp, but I heard that android falls back to xhr anyways.

socket.on('connect',function (data) {
            socket.emit('setNickAndRoom', {nick: nick}, function(response){
//response. nothing :(.
});
});

client.on("setNickAndRoom", function(nick, fn,_){
//etc etc

fn({msg :nick});
});

This works on every browser (even mobile safari, mobile FF, mobile chrome beta). I have to refresh android browser 4-5 times for it to finally connect. BTW, im using streamline js (_)

UPDATE This seems to happen on wifi only

2012-04-05 19:20
by re1man
did you configure the server? Where are you deploying to - JakeWilson801 2012-04-18 07:02
when you put a bounty it cut your old rep immediatel - UmNyobe 2012-04-23 08:37


3

Limited options at this time:

http://code.google.com/p/weberknecht/

https://github.com/TooTallNate/Java-WebSocket

https://github.com/Gottox/socket.io-java-client

sound right as far as WebSockets go. Socket.IO's specific wire protocol do not appear to have been implemented in Java yet, so you may have to deal with that yourself.

2012-04-18 07:06
by JakeWilson801


1

Following the socket io website, it seems you are not using it right.

Try changing socket.on('connect',function (data) {

to

socket.on('connection',function (data) {

2012-04-24 05:39
by Ilya Gazman


0

For what it's worth, this simple example below works on my Android browser. Let us know if there's anything specific you need, that's not covered below -- important: Change the IP number and port to whatever fits your environment:

var express = require('express'),
    socketio = require('socket.io'),
    app = express.createServer(),
    io = socketio.listen(app);

var index = "<!doctype html>\
<html>\
  <head>\
    <script src=/socket.io/socket.io.js></script>\
    <script>\
        var socket = io.connect('http://10.0.1.29:3000');\
        function send() {\
            socket.emit('foo', 'Ben', function(data) {\
                alert(data);\
            });\
        }\
    </script>\
  </head>\
  <body>\
  <button onclick='send();'>Send</button>\
</html>";

app.get('/', function(req, res) {
    res.send(index);
});

io.sockets.on('connection', function(socket) {
    socket.on('foo', function(name, f) {
        f('Hello ' + name);
    });
});

app.listen(3000);
2012-04-18 10:54
by Linus Gustav Larsson Thiel
the problem I'm having is that I have to refresh the android browser, 4-5 times for it to actually connect. I added the 'connect' logic above. I'm connect on my server url, and port 80, so I dont declare the port in io.connect - re1man 2012-04-18 16:53
Ads