I am really struggling with opening a socket connection using sails.io and android. What I am trying to achieve at the moment is simply to print the socketid in the console of the sails.js server.
Android Side:
I am using nkzwa's socket.io.client library ( compile 'com.github.nkzawa:socket.io-client:0.4.2')
This is the code that I am using in android inside an AsyncTask:
private Socket mSocket;
{
try {
mSocket = IO.socket("http://192.168.0.80:3000/batches/");
} catch (URISyntaxException e) {}
}
@Override
protected Void doInBackground(Void... params) {
mSocket.connect();
mSocket.emit("getSocketID");
}
and my batchescontroller looks like this:
module.exports = {
getSocketID: function(req, res) {
if (!req.isSocket) return res.badRequest();
var socketId = sails.sockets.id(req.socket);
// => "BetX2G-2889Bg22xi-jy"
console.log(socketId)
return res.ok('My socket ID is: ' + socketId);
}
}
When running the task I thought that I would get the console log outputted in my sails instance.
Can anyone see what I am doing wrong?