Socket.io-client-java: Socket disconnecting with transport error in android

Created on 26 Mar 2018  路  3Comments  路  Source: socketio/socket.io-client-java

I am trying to connect a socket in my app which is working very well in my iOS app but disconnects with "Transport error" in the android one.

The code for the iOS one I used is
"[.reconnects(true), .reconnectAttempts(5), .reconnectWait(3), .log(false), .forcePolling(false), .forceWebsockets(false),.forceNew(false),.secure(false),.selfSigned(false),.path("/socket.io-client/")]

The android code is
IO.setDefaultOkHttpCallFactory(okHttpClient);
IO.setDefaultOkHttpWebSocketFactory(okHttpClient);
IO.Options opts = new IO.Options();
opts.path = "/socket.io-client";
opts.secure = false;
opts.transports = new String[]{Polling.NAME};
opts.reconnection = true;
opts.forceNew = true;
opts.callFactory = okHttpClient;
opts.webSocketFactory = okHttpClient;
mSocket = IO.socket(Urls.socket_url, opts);

Most helpful comment

try WebSocket.NAME instead of Polling.NAME,

opts.transports = new String[]{WebSocket.NAME};

This fixed my problem.

All 3 comments

try WebSocket.NAME instead of Polling.NAME,

opts.transports = new String[]{WebSocket.NAME};

This fixed my problem.

@khaleeljageer by applying
opts.transports = new String[]{WebSocket.NAME};

ping timeout issue comes up and solution for the same?

hello guys,

I try to create a connection using sockets.io client. it work on the ios however in the android it has a message shows websocket error

here is my code
var socket = io('https://localhost:8888',{transports: ['websocket'],rejectUnauthorized:false,secure:true});

version

"socket.io": "^2.1.1",
"socket.io-client": "^2.1.0"

is there a configuration in the android where I can fix this error/

thak you

Was this page helpful?
0 / 5 - 0 ratings