androidsocket.iotransport

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.


Solution

  • 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