How to set transports for SocketIO in Android?

谁说胖子不能爱 提交于 2019-12-11 00:00:00

问题


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

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