Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

android socketio aways disconnect transport error #491

Open
164966580 opened this issue Jan 19, 2018 · 11 comments
Open

android socketio aways disconnect transport error #491

164966580 opened this issue Jan 19, 2018 · 11 comments

Comments

@164966580
Copy link

Hello. Please help me.
Android Socketio "io.socket:socket.io-client:0.9.0".
Server: netty-socketio/1.7.7
aways from onConnect is ok to diconnected transport error。May not upgrade to websocket。Anybody encountered the same problem?Pelase help。Thank U

@Bendor
Copy link

Bendor commented Jan 23, 2018

the same problem(

@AhmedX6
Copy link

AhmedX6 commented Feb 4, 2018

same problem here ...

@s9443112
Copy link

same problem here .... please help

@TonyT9
Copy link

TonyT9 commented Apr 2, 2018

Set the transports explicitly to websockets when connecting from the client. As in:
io(YOUR_SERVER_URL_HERE,{
transports: ['websocket']
})

The default is ['polling', 'websocket']

@khaleeljageer
Copy link

I configured my code like this,
IO.Options options = new IO.Options();
options.transports = new String[]{WebSocket.NAME};
options.query = "token=my custom token";
Socket mSocket = IO.socket("https://mydomain.com/", options);

Fixed my problem...

@164966580
Copy link
Author

Sorry, late reply. I solved the problem because I used Charles, which caused the problem. When I turned off the Charles agent, the problem no longer appeared. I don't know exactly why, but the problem is solved.Thanks for your reply

@s9443112
Copy link

s9443112 commented Apr 9, 2018 via email

@chenguozhi
Copy link

I also encountered ["transport error"] in onDisConnect, the client accidentally disconnect after a period of time, the client version was 1.0.0, and then it was changed to 0.8.3, still no use, can someone help me?

我也遇到["transport error"] 在onDisConnect,客户端在使用一段时间后,偶然 disconnect 了,客户端版本是1.0.0,后来改为0.8.3,还是没有用, 有人能帮助我吗

@chenguozhi
Copy link

  opts.transports = new String[]{WebSocket.NAME};我也加了这个设置,仍然无用

Opts. Transports = new String [] {WebSocket. NAME}; I also added this setup, which is still useless.

@LeeBoonKong
Copy link

LeeBoonKong commented Nov 9, 2018

Dear all,
It seems like the problem would probably be the configuration of okHttp.

           OkHttpClient okHttpClient = new OkHttpClient.Builder()
                    .hostnameVerifier(hostnameVerifier)
                    .sslSocketFactory((SSLSocketFactory) SSLSocketFactory.getDefault(), trustManager)
                    .connectTimeout(20, TimeUnit.SECONDS)
                    .writeTimeout(1, TimeUnit.MINUTES)
                    .readTimeout(1, TimeUnit.MINUTES)
                    .build();
            IO.setDefaultOkHttpCallFactory(okHttpClient);
            IO.setDefaultOkHttpWebSocketFactory(okHttpClient);

By adding connectTimeout, and providing it a long writeTimeout and readTimeout seems to work for me.
Note: There is a heartbeat mechanism that you can specify on Socket.IO Server, which I think the value here should tally with your server's pingTimeout value.
Note2: The default values of these parameters in okHttp is 10000ms or 10 seconds.

@rohankandwal
Copy link

Dear all,
It seems like the problem would probably be the configuration of okHttp.

           OkHttpClient okHttpClient = new OkHttpClient.Builder()
                    .hostnameVerifier(hostnameVerifier)
                    .sslSocketFactory((SSLSocketFactory) SSLSocketFactory.getDefault(), trustManager)
                    .connectTimeout(20, TimeUnit.SECONDS)
                    .writeTimeout(1, TimeUnit.MINUTES)
                    .readTimeout(1, TimeUnit.MINUTES)
                    .build();
            IO.setDefaultOkHttpCallFactory(okHttpClient);
            IO.setDefaultOkHttpWebSocketFactory(okHttpClient);

By adding connectTimeout, and providing it a long writeTimeout and readTimeout seems to work for me.
Note: There is a heartbeat mechanism that you can specify on Socket.IO Server, which I think the value here should tally with your server's pingTimeout value.
Note2: The default values of these parameters in okHttp is 10000ms or 10 seconds.

This really worked for me.. Adding timeout using OKHTTP3, that stabilised connection. Didn't get timeout for 15 20 minutes. I didn't use HostNameVerifier and SSLSocketFactory though.

darrachequesne added a commit to socketio/engine.io-client-java that referenced this issue Jul 3, 2022
With the previous value (10 seconds by default), a connection
established with HTTP long-polling was closed if the server did not
send any packet for 10 seconds (the HTTP request would timeout from the
client side).

It will now default to 1 minute, which is above the
`pingInterval + pingTimeout` value from the server.

Note: the connectTimeout and writeTimeout options are left as is (10
seconds), but you may need to increase them depending on your use case:

```
OkHttpClient client = new OkHttpClient.Builder()
	.connectTimeout(20, TimeUnit.SECONDS)
	.readTimeout(1, TimeUnit.MINUTES)
	.writeTimeout(1, TimeUnit.MINUTES)
        .build();
```

Related:

- socketio/socket.io-client-java#491
- socketio/socket.io-client-java#660
darrachequesne added a commit to socketio/engine.io-client-java that referenced this issue Jul 10, 2022
With the previous value (10 seconds by default), a connection
established with HTTP long-polling was closed if the server did not
send any packet for 10 seconds (the HTTP request would timeout from the
client side).

It will now default to 1 minute, which is above the
`pingInterval + pingTimeout` value from the server.

Note: the connectTimeout and writeTimeout options are left as is (10
seconds), but you may need to increase them depending on your use case:

```
OkHttpClient client = new OkHttpClient.Builder()
	.connectTimeout(20, TimeUnit.SECONDS)
	.readTimeout(1, TimeUnit.MINUTES)
	.writeTimeout(1, TimeUnit.MINUTES)
        .build();
```

Related:

- socketio/socket.io-client-java#491
- socketio/socket.io-client-java#660

Backported from fb531fa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants