从客户端发送的Socket请求(的iOS&安培; Android的),以Sails.js服务器 [英] Sending Socket request from Client (iOS & Android) to Sails.js Server

查看:245
本文介绍了从客户端发送的Socket请求(的iOS&安培; Android的),以Sails.js服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用socket.io与iOS和Android应用程序,但有一些问题在这里。我问,如果有任何人谁实际上有解决方案。

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.

我如何发送socket.io请求从客户端(IOS,Android的),我认为这是socket.io库,为iOS和Android和iOS的lib已经的SendEvent /留言/ JSON方法。但是,我无法找到一个办法让在帆的事件。 https://github.com/pkyeck/socket.IO-objc https://github.com/koush/AndroidAsync 那么,有没有,我可以从客户端发送socket.io事件什么办法?因此,我可以使用它像

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();
  },

有什么办法,我可以知道当前套接字连接是由客户端(IOS / Android的)或Web前端?

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);

  },

当我连接插座的服务器,我需要URL连接。我可以在URL中添加一些PARAMS。有没有什么办法,我可以知道哪些参数,我用与服务器的连接?

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?

感谢。

推荐答案

从iOS系统Sails.js服务器(使用的 Socket.io

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];

从安卓到Sails.js服务器(使用 AndroidAsync ,感谢的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);

帆控制器

action: function(req, res) {
    var data1 = req.param('param1');
    var data2 = req.param('param2');
    sails.log.debug(req.socket);
    return res.ok();
}

这篇关于从客户端发送的Socket请求(的iOS&安培; Android的),以Sails.js服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆