I tried to retrieve socket from my sails server but never success. How to retrieve socket from sails server? i search every where but nothing found.
--Update--
i need some function to retrieve socket from sails which using
socket.io. My code was success to connect with sails server, but not
receieve the socket. If i implement my code for socket io only, this
will work, but for sails this code never retrieve the socket.
try {
JSONObject sendData = new JSONObject();
sendData.put("url","/user/socket");
mSocket.emit("get", sendData, new Ack() {
@Override
public void call(Object... args) {
Log.d("AC",args[0].toString());
}
});
}catch (JSONException jsonEx){
jsonEx.printStackTrace();
}
//mSocket.on("/user/hello", handleIncomingMessages);
mSocket.on("hello", handleIncomingMessages);
mSocket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.i("Connected","Yes");
}
});
mSocket.on(Socket.EVENT_CONNECT_ERROR, new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.i("Connecting Error",args[0].toString());
}
});
mSocket.on(Socket.EVENT_RECONNECTING, new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.i("Reconnecting","Yes");
}
});
mSocket.connect();
For the one who downvote without any confirmation, i dunno what u want and what u after. I was solved my problem and i hope it can help someone. You just need to move ur code for handleincoming messages after retrieve respon from requesting cache to connect server.
try {
JSONObject sendData = new JSONObject();
sendData.put("url","/user/socket");
mSocket.emit("get", sendData, new Ack() {
@Override
public void call(Object... args) {
Log.d("AC",args[0].toString());
mSocket.on("hello", handleIncomingMessages);
}
});
}catch (JSONException jsonEx){
jsonEx.printStackTrace();
}
I hope it can help someone with same problem.