[TIMOB-26730] Android: Cannot use Socket.io module, closes connection after first message
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Not Our Bug |
Resolution Date | 2019-02-15T18:00:37.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Android |
Labels | n/a |
Reporter | Hans Knöchel |
Assignee | Jan Vennemann |
Created | 2019-01-15T17:54:39.000+0000 |
Updated | 2019-02-15T18:00:37.000+0000 |
Description
While working with Socket.io on iOS works fine, we are running into critical issues when using the module on Android. The first message works, after that the following error occurs and the communication is broken.
[ERROR] Error in socket connection
[ERROR] {"message":"xhr poll error"}
[ERROR] Error in socket connection
[ERROR] Error in socket connection
[ERROR] {"message":"xhr poll error"}
[WARN] W/com.appc.app: No such thread id for suspend: 29
[WARN] System: A resource failed to call response.body().close().
[INFO] chatty: uid=10108(com.appc.app) OkHttp Connecti identical 1 line
[WARN] System: A resource failed to call response.body().close().
[ERROR] Error in socket connection
[ERROR] {"message":"xhr poll error"}
[ERROR] Error in socket connection
[ERROR] {"message":"xhr poll error"}
[ERROR] Error in socket connection
[ERROR] {"message":"xhr poll error"}
[ERROR] Error in socket connection
[ERROR] {"message":"xhr poll error"}
[ERROR] Error in socket connection
[ERROR] {"message":"xhr poll error"}
[ERROR] Error in socket connection
[ERROR] {"message":"xhr poll error"}
[ERROR] Error in socket connection
[ERROR] {"message":"xhr poll error"}
[ERROR] Error in socket connection
[ERROR] {"message":"xhr poll error"}
[ERROR] Error in socket connection
[ERROR] {"message":"xhr poll error"}
[ERROR] Error in socket connection
[ERROR] {"message":"xhr poll error"}
[ERROR] Error in socket connection
[ERROR] {"message":"xhr poll error"}
[ERROR] Error in socket connection
[ERROR] {"message":"xhr poll error"}
[ERROR] Error in socket connection
[ERROR] {"message":"xhr poll error"}
[ERROR] Error in socket connection
[ERROR] {"message":"xhr poll error"}
[ERROR] Error in socket connection
[ERROR] {"message":"xhr poll error"}
[ERROR] Error in socket connection
[ERROR] {"message":"xhr poll error"}
[ERROR] Error in socket connection
[ERROR] {"message":"xhr poll error"}
[ERROR] Error in socket connection
[ERROR] {"message":"xhr poll error"}
[ERROR] Error in socket connection
[ERROR] {"message":"xhr poll error"}
[ERROR] Error in socket connection
[ERROR] {"message":"xhr poll error"}
Maybe the OKHTTP library used in the core clashes with this one?
Google's Android OS uses the okhttp library internally, which is what the Android
HttpUrlConnection
Java class uses under the hood. So, this is most likely an okhttp library version conflict. Unfortunately, the only 100% ensured way of avoiding this issue is to either:Recompile the entire okhttp library under a different namespace.
Remove the module's okhttp library usage and use some other API.
I'm curious. What do you need from "ti.socket" that our coreTi.Network.Socket
doesn't offer?Thanks for the suggestion Josh! We didn't try Ti.Network.Socket so far, because the official socket.io library seemed to be the best match here and is pretty performant on iOS. Regarding the conflict: The module uses okhttp-3.11.0.jar and okio-1.14.1.jar, so maybe it's something there. We will also give the ti.network socket a shot!
[~jquick] that module is for [socket.io](https://socket.io/), not just a simple socket ;) To use
Ti.Network.Socket
one would have to write a WebSocket implementation first and then use that to implement a socket.io client.Oh gotcha. You're after the WebSocket protocol. So, we could try updating the okhttp library to the newest version. Assuming that it's backward compatible with older Android OS versions and it doesn't conflict with what Google is using. It's worth a try. Although their newest version's min Android version supported is 5.0, which doesn't line-up with Titanium's min version of 4.4. http://square.github.io/okhttp
This is most likely due to a nginx reverse proxy setup. This prevents socket.io from successfully upgrading the http connection to a websocket connection. The iOS client handles this transparently by remaining in http polling mode. The Android client however seems to have issues with an upgrade error. Please see the following link and see if your server setup is properly configured: https://www.nginx.com/blog/websocket-nginx/
This was indeed caused by a missing configuration in the nginx reverse proxy. Closing since it was fixed on the server side.