Socket.io-client-java: Always getting 401~BADFORMAT exception

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

I have tried to call this socket api with android its not working but with swift its working properly, can anyone please help me what i am doing wrong here?

below is the the code which i am doing, also please suggest me how to pass parameters into emit.

final Socket socket;
try {

        /*socket.emit('SubAdd', { subs: ['0~Poloniex~BTC~USD'] } ); */

        IO.Options options = new IO.Options();
        options.transports = new String[]{WebSocket.NAME};
        socket = IO.socket("https://streamer.cryptocompare.com", options);

        JSONObject object = new JSONObject();
        try {
            object.put("subs", "[5~CCCAGG~BTC~USD]");
            socket.emit("SubAdd", object.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }


        socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
            @Override
            public void call(Object... args) {

            }
        }).on("m", new Emitter.Listener() {

            @Override
            public void call(Object... args) {
                Log.e("response", args[0].toString());
            }

        }).on("event", new Emitter.Listener() {

            @Override
            public void call(Object... args) {
            }


        }).on(Socket.EVENT_DISCONNECT, new Emitter.Listener() {

            @Override
            public void call(Object... args) {
            }

        });
        socket.connect();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

Most helpful comment

This should fix your problem.

JSONObject object = new JSONObject();
JSONArray arr = new JSONArray();
try {
    arr.put("5~CCCAGG~BTC~USD");
    object.put("subs", arr);
    socket.emit("SubAdd", object);
} catch (JSONException e) {
    e.printStackTrace();
}

All 4 comments

This should fix your problem.

JSONObject object = new JSONObject();
JSONArray arr = new JSONArray();
try {
    arr.put("5~CCCAGG~BTC~USD");
    object.put("subs", arr);
    socket.emit("SubAdd", object);
} catch (JSONException e) {
    e.printStackTrace();
}

@gtaylor5 It's work for me!!!, thank you very much!

Thanks for the awesome help @gtaylor5 .

This issue can be closed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jingfreeks picture jingfreeks  路  3Comments

b95505017 picture b95505017  路  12Comments

commjoen picture commjoen  路  5Comments

jaumard picture jaumard  路  4Comments

abhilash29 picture abhilash29  路  6Comments