1

I am trying to change the default AndroidAsync websocket initial connection timeout of 30 seconds. This is the working version with the default timeout:

AsyncHttpClient.getDefaultInstance().websocket(connectionURI.toString(), null, this);

I would like to change the timeout. This is what I expected to work:

int timeout_ms = 20000;
AsyncHttpGet request = new AsyncHttpGet(connectionURI.toString());
request.setTimeout(timeout_ms);
AsyncHttpClient.getDefaultInstance().websocket(request, null, this);

This results in an java.lang.IllegalArgumentException: invalid uri=ws://exampleserver.com:80/test middlewares=[com.koushikdutta.async.http.HttpTransportMiddleware@1e2543c8, com.koushikdutta.async.http.spdy.SpdyMiddleware@2534fc61, com.koushikdutta.async.http.AsyncSocketMiddleware@107b3386]

Note that exactly the same connectionURI string is successful in the first case, but not the second.

Is there a way to change the timeout of the AndroidAsync websocket?

mattm
  • 5,851
  • 11
  • 47
  • 77

2 Answers2

0

This hack helped me.You need to pass http or htpps protocol.

    AsyncHttpGet request = new AsyncHttpGet("ws://xxx.xxx.x.xx:8500".replace("ws://", "http://").replace("wss://", "https://"));
    request.setTimeout(3000);

    AsyncHttpClient asyncHttpClient = AsyncHttpClient.getDefaultInstance();
    asyncHttpClient.websocket(request, null, webSocketConnectCallback);
Igori S
  • 123
  • 8
-2

It seems to be unresolved issue by Koush https://github.com/koush/AndroidAsync/issues/340