Closed timvermeulen closed 7 years ago
This library isn't a WebSocket client. Check out https://github.com/daltoniam/Starscream (It's what this library uses for WebSocket.)
@timvermeulen Hey Tim, did you manage to connect in the end? I'm having issues connecting to the same websocket but I'm trying in Python. Just wanted to follow up on this as you may have some useful info for me. Thanks!
@yudevit I haven't attempted it since, sorry about that 😕
Hey @timvermeulen replace URL(string: "wss://streamer.cryptocompare.com")! with URL(string: "https://streamer.cryptocompare.com/")! and it will connect without any issue.
But I am stuck at
self.socket?.emitWithAck("SubAdd", [ "subs" : ["0~CCCAGG~BTC~USD"]]).timingOut(after: 0, callback: { (data) in print("data is : (data)") })
callback never called :(
yeah finally @timvermeulen @nuclearace @yudevit @IdeaCentricity @banjun ,
import SocketIO
class SocketIOManager :NSObject{
var data:NSString?
static let sharedInstant = SocketIOManager()
var socket: SocketIOClient = SocketIOClient(socketURL: NSURL(string: "https://streamer.cryptocompare.com")! as URL, config: [.log(true), .forcePolling(true)])
override init() {
super.init()
print("init called")
let dict = [ "subs" : ["5~CCCAGG~BTC~USD"]]
socket.on(clientEvent: .connect) {data, ack in
print("socket connected \(data) \(ack)")
self.socket.emit("SubAdd", dict)
}
socket.on("m", callback: {data,ack in
print("M printed")
print("M \(data)")
let myString: String = String(describing: data[0])
if myString == "3~LOADCOMPLETE"{
self.socket.emit("SubRemove", dict)
// SocketIOManager.init()
}else {
var myStringArr = myString.components(separatedBy: "~")
print("Price Updated \(myStringArr[5])")
}
})
}
func establishConnection() {
socket.connect()
}
func closeConnection() {
socket.disconnect()
}
}
Thanks @pandeyshivang, works great!
@pandeyshivang have you do same thing in android because in iOS your solution works but in android it is not working .
@imobdevtech follow this(Swift) implemention in JAVA and use https://github.com/socketio/socket.io-client-java
@pandeyshivang we already follow all the step which is in swift but we stuck at emit statement , everytime we got 1 - bad request . can you please share that portion code in android if feasible
@imobdevtech wait...i'll share code
@pandeyshivang finally find the solution thank you for your support
@imobdevtech i think you were missing or wrong emit before soket.onlistener callback.
@pandeyshivang finally find the solution thank you for your support
could you please post the correct solution you found. I'm having the same issue here.
Found the right way for Java version. The following should work:
JSONObject object = new JSONObject(); JSONArray arr = new JSONArray(); try { arr.put("11~BTC'"); object.put("subs", arr); socket.emit("SubAdd", object); } catch (JSONException e) { e.printStackTrace(); }
Found the right way for Java version. The following should work:
JSONObject object = new JSONObject(); JSONArray arr = new JSONArray(); try { arr.put("11~BTC'"); object.put("subs", arr); socket.emit("SubAdd", object); } catch (JSONException e) { e.printStackTrace(); }
please try to use hashmap and arraylist instead of jsonobject and array
@pandeyshivang The performance is the same as HashMap and no extra overhead. Also, considering that we are dealing with actual JSON on the request, I highly recommend it. The actual docs use JSONObject too. https://github.com/socketio/socket.io-client-java - check the readme.
I'm probably missing something obvious. The url is wss://streamer.cryptocompare.com, as can be found on their website. I can connect to it fine using this online socket.io client, but I can't get it to work using this library:
The logs I'm getting are