Skip to content Skip to sidebar Skip to footer

Sending Socket Request From Client (ios & Android) To Sails.js Server

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 fro

Solution 1:

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 = newJSONArray();
JSONObject obj = newJSONObject();
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();
}

Post a Comment for "Sending Socket Request From Client (ios & Android) To Sails.js Server"