简体   繁体   中英

How to set transports for SocketIO in Android?

I spend a long time to research about transports in SocketIO Android. I need set transports for Options is "websocket" instead of "polling", Maybe Socketio set default transport is polling.

Any help appreciated, thanks.

You have to use the transports option:

import io.socket.engineio.client.transports.WebSocket;

//...
IO.Options opts = new IO.Options();
opts.transports = new String[] { WebSocket.NAME };
Socket mSocket = IO.socket("http://example.com/", opts);

For polling:

import io.socket.engineio.client.transports.Polling;
//...

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

You can check this socket.io test

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM