5

I have an application using socket.io, and socket.emit() is not working from mobile chrome (on Android and iOS). I can see that the socket.emit() is getting executed in the browser. But my server-side console.log statements in socket.on() are not running, so I think messages are not getting there. I see no errors in the console either.

Interestingly though, everything works fine in incognito mode, plus all modes in other mobile browsers like Safari.

Any solutions, or help with debugging would be helpful.

EDIT:

CLIENT SIDE CODE

$(document).ready(function(){
    socket = io();
    $(".check").on("submit", function(event){
        event.preventDefault();
        ga('send','event','evt','evt123');
        socket.emit('checkRoom', { rId: "12345", pId: "johndoe"});
    });
});

SERVER SIDE CODE

io.on('connection', function(socket) {
    console.log('a user connected');

    socket.on('check',function(e){
        console.log('Entered check');
        socket.emit('check','server message');
    });
});

EDIT2:

I manually specified the socket.io-1.3.5.js file on the client side (instead of using the default /socket.io/socket.io.js) and started seeing this error in the console:

WebSocket connection to 'ws://mydomain.com/socket.io/?EIO=3&transport=websocket&sid=wr8UpsT45lrWHtpMACJs' failed: Error in connection establishment: net::ERR_CONNECTION_TIMED_OUT
Deepak Joy Cheenath
  • 5,796
  • 5
  • 25
  • 29
  • We will likely need to see the relevant code for us to have any idea what might be going on here. – jfriend00 May 24 '15 at 03:40
  • How exactly do you see that `socket.emit` is working from client? Did you put a `console.log` right before or after it? Are you still getting "a user connected" on server meaning the socket does connect but emit from client doesn't get received? Try putting a couple of `socket.emit/on('test')` (with appropriate console log messages) on both server and client that trigger without any interaction just to see if the communication happens at least at first contact, or whether the problems starts later. – laggingreflex May 24 '15 at 13:30
  • @laggingreflex: I've used breakpoints to see that the code is getting to `socket.emit`. I have tried with very simple code to check if the first contact is happening, and I can see that messages are not getting to the server. – Deepak Joy Cheenath May 25 '15 at 03:01

1 Answers1

0

Some of the mobile networks proxy requests over port 80, which can break web sockets. That wouldn't explain why it would work in other browsers or in incognito, but you can test this hypothesis, by moving your server and client to connect over a different port, eg. 81.

jastr
  • 881
  • 1
  • 9
  • 19