How are timeouts set for AndroidAsync websockets?

假如想象 提交于 2019-12-13 02:31:49

问题


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?


回答1:


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);



回答2:


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



来源:https://stackoverflow.com/questions/29548199/how-are-timeouts-set-for-androidasync-websockets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!