Gottox / socket.io-java-client

Socket.IO Client Implementation in Java
MIT License
949 stars 387 forks source link

no connection on cellular network #22

Open orangeman opened 12 years ago

orangeman commented 12 years ago

establishing a socket.io connection works beautifully in the android emulator and on devices with WiFi. But it seems not to be able to connect when on HSPA. A least onConnect() is not called https://github.com/ANDLABS-Git/studio-lounge-droid/blob/master/src/eu/andlabs/studiolounge/gcp/GCPService.java#L59

Did anyone encounter similar issues?

Could this be a port / NAT / gateway issue with the mobile network operator? (O2 Germany in this case) But the web/browser frontend http://happylog.jit.su is working on the exact same device with the exact same HSPA connection and the exact same socket.io backend :/ Could this be a fallback to a different transport in the browser?

orangeman commented 12 years ago

update: it seems to be the mobile network operator blocking non-http traffic on port 80. When running socket.io on a different port it works fine.

Maybe it would help to call onError() or throw some Exception after some timeout to notify that no connection can be established.

Gottox commented 12 years ago

Hi @orangeman!

Thanks for using socket.io-java-client. This is still an issue, socket.io-java-client should switch to xhr when websocket does not work.

For now, can you deactivate the websocket protocol on the serverside and retry if xhr works? - This should already work with socket.io-java-client.

friederikewild commented 11 years ago

Hi @Gottox,

I'm interested in using the socket.io-java-client for an android game. I am wandering if the problem reported by @orangeman is still an open issue? If so - is a fix using xhr in this case or another http long polling solution planned to be included soon?

sooraj-e commented 11 years ago

i had similar issue and enabling xhr mode worked like a charm.

sooraj-e commented 11 years ago

is there any option in client to explicitly set the connection mode? So that i can set websocket for Wifi and xhr for 3G?

xionglun commented 11 years ago

It works well at url like: http://sample.com:8888/ but cann't connect http://mysocket.sample.com/. At port 8888, I use a nodejs app with socket.io, and I use nginx as a proxy. Maybe nginx cause this error. Is it true?

chrislarcombe commented 11 years ago

I have the same problem. It works fine on WiFi connection, but not the phone's network connection. There are no errors on the client-side. When I connect to the server (using the phone's network) on port 8888 or port 80 I have the same issue: no connection established and no error messages. However, on the server-side I get some debugging information when attempting to connect:

debug - client authorized info - handshake authorized VQ3xAx27EFBM_ygGm2Lb debug - setting request GET /socket.io/1/websocket/VQ3xAx27EFBM_ygGm2Lb debug - set heartbeat interval for client VQ3xAx27EFBM_ygGm2Lb warn - websocket connection invalid info - transport end (undefined) debug - set close timeout for client VQ3xAx27EFBM_ygGm2Lb debug - cleared close timeout for client VQ3xAx27EFBM_ygGm2Lb debug - cleared heartbeat interval for client VQ3xAx27EFBM_ygGm2Lb debug - setting request GET /socket.io/1/websocket/VQ3xAx27EFBM_ygGm2Lb debug - set heartbeat interval for client VQ3xAx27EFBM_ygGm2Lb warn - websocket connection invalid info - transport end (undefined) debug - set close timeout for client VQ3xAx27EFBM_ygGm2Lb debug - cleared close timeout for client VQ3xAx27EFBM_ygGm2Lb debug - cleared heartbeat interval for client VQ3xAx27EFBM_ygGm2Lb debug - setting request GET /socket.io/1/websocket/VQ3xAx27EFBM_ygGm2Lb debug - set heartbeat interval for client VQ3xAx27EFBM_ygGm2Lb warn - websocket connection invalid info - transport end (undefined) debug - set close timeout for client VQ3xAx27EFBM_ygGm2Lb debug - cleared close timeout for client VQ3xAx27EFBM_ygGm2Lb debug - cleared heartbeat interval for client VQ3xAx27EFBM_ygGm2Lb debug - setting request GET /socket.io/1/websocket/VQ3xAx27EFBM_ygGm2Lb debug - set heartbeat interval for client VQ3xAx27EFBM_ygGm2Lb warn - websocket connection invalid info - transport end (undefined) debug - set close timeout for client VQ3xAx27EFBM_ygGm2Lb debug - cleared close timeout for client VQ3xAx27EFBM_ygGm2Lb debug - cleared heartbeat interval for client VQ3xAx27EFBM_ygGm2Lb debug - setting request GET /socket.io/1/websocket/VQ3xAx27EFBM_ygGm2Lb debug - set heartbeat interval for client VQ3xAx27EFBM_ygGm2Lb warn - websocket connection invalid info - transport end (undefined) debug - set close timeout for client VQ3xAx27EFBM_ygGm2Lb debug - cleared close timeout for client VQ3xAx27EFBM_ygGm2Lb debug - cleared heartbeat interval for client VQ3xAx27EFBM_ygGm2Lb debug - setting request GET /socket.io/1/websocket/VQ3xAx27EFBM_ygGm2Lb debug - set heartbeat interval for client VQ3xAx27EFBM_ygGm2Lb warn - websocket connection invalid

This keeps looping until I shut down the client app on the phone.

chrislarcombe commented 11 years ago

Am attempting to use XHR - it works in my web client:

debug - xhr-polling received data packet 5:::{"name":"receiveMessage","args":["larky"]} Message: larky

The server responds by recognising the message.

However, when the phone sends the same message the server-side 'on event' function is not called:

debug - xhr-polling received data packet 5:::{"args":["larky"],"name":"receiveMessage"} debug - clearing poll timeout

The debugging looks identical apart from the order of the event name and args. I don't think this should matter?

This is the server-side code:

socket.on('receiveMessage', function(message) { console.log("Message:", message); }

Problem: not being called when phone sends message.

chrislarcombe commented 11 years ago

Update: for websockets (not XHR) I can confirm the error is the same (warn websocket connection invalid) using a different library: https://github.com/koush/AndroidAsync

Although the error message warning does not loop. It only occurs about 4 times... I hope this helps.

(this was on port 80, and network providor giffgaff which I think is O2 network)

chrislarcombe commented 11 years ago

Good news: I managed to get mine to work by changing the port to 443. Apparently it is something to do with the network, and on that port it's not getting blocked or messed up.

Here is some more information: http://stackoverflow.com/questions/5557776/websockets-over-a-3g-connection