Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26730] Android: Cannot use Socket.io module, closes connection after first message

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionNot Our Bug
Resolution Date2019-02-15T18:00:37.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
Labelsn/a
ReporterHans Knöchel
AssigneeJan Vennemann
Created2019-01-15T17:54:39.000+0000
Updated2019-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?

Comments

  1. Joshua Quick 2019-01-18

    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 core Ti.Network.Socket doesn't offer?
  2. Hans Knöchel 2019-01-18

    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!
  3. Jan Vennemann 2019-01-18

    [~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.
  4. Joshua Quick 2019-01-18

    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
  5. Jan Vennemann 2019-02-07

    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/
  6. Jan Vennemann 2019-02-15

    This was indeed caused by a missing configuration in the nginx reverse proxy. Closing since it was fixed on the server side.

JSON Source