Sending a Socket Request from a Client (iOS and Android) to a Sails.js Server

I am trying to use socket.io with the iOS and Android App, but there are some problems here. I ask if there is anyone who has solutions.

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

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

Is there a way to find out if the current socket connection is connected to the client (ios / android) or the web interface?

 onConnect: function(session, socket) { console.log(session); console.log(socket); }, 

when I connect the socket to the server, I need the url to connect. I can add some parameters to the URL. Is there any way to find out what parameters I used to connect to the server?

Thanks.

+1
source share
1 answer

From iOS server to Sails.js (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(); } 
+5
source

Source: https://habr.com/ru/post/988672/


All Articles