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();
}
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.
Most helpful comment
This should fix your problem.