1

I'm trying to use socket.io with iOS and Android App, but there is some problem here. I'm asking if there is anyone who actually has solutions.

How can I send socket.io request from client (iOS, Android), I think there is socket.io libraries for iOS and Android and iOS lib has sendEvent/Message/JSON methods. However, I couldn't find a way to get the events at the sails. https://github.com/pkyeck/socket.IO-objc https://github.com/koush/AndroidAsync So is there any way that I can send socket.io event from client? So I can use it like

join: function (req, res) {
    sails.sockets.join(req.socket, req.param('room'));
    return res.ok();
  },

Is there any way that I can know whether current socket connection is from client (ios/android) or web front end?

onConnect: function(session, socket) {

    console.log(session);
    console.log(socket);

  },

when I connect socket with server, I need url to connect. I can add some params at the url. Is there any way that I can know which parameters I've used to connect with server?

Thanks.

1 Answer 1

6

From iOS to Sails.js Server (Using Socket.io)

SocketIO *socket;
NSString *url = [NSString stringWithFormat:@"/v1/controller/action?param1=%@&param2=%@", @"data1", @"data2"];
NSDictionary *params = @{@"url" : url};
[socket sendEvent:@"get" withData:data];

From Android to Sails.js Server (Using AndroidAsync, thanks to ArtworkAD)

JSONArray arr = new JSONArray();
JSONObject obj = new JSONObject();
obj.put("url", String.format("/v1/controller/action?param1=%s&param2=%s", "data1", "data2"));
arr.put(obj);
socketClient.emit("get", arr);

Sails Controller

action: function(req, res) {
    var data1 = req.param('param1');
    var data2 = req.param('param2');
    sails.log.debug(req.socket);
    return res.ok();
}
2
  • 1
    too bad AndroidAsync has almost no examples for Android in socket.io. I can't create the socketClient, don't know how.... Commented Nov 7, 2014 at 21:18
  • @Francisco Corrales Morales. You'd probably need to import a SocketIO library for android. [link] (github.com/socketio/socket.io-client-java) can be a good start. I have used this in several android application and works out of the box.
    – burntblark
    Commented Sep 4, 2017 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.