问题
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.
回答1:
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
来源:https://stackoverflow.com/questions/44015305/how-to-set-transports-for-socketio-in-android