2

have any idea how to make a socket.get() request in android?

I try this:

JSONObject obj = new JSONObject();
obj.put("url","/controller/action");
socketClient.emit("get",obj);

And the server response is:

Error (SAILS:HOOK:SOCKETS:PARSE_VIRTUAL_REQ):: Failed to parse incoming socket.io request
...
details: 'Sails v0.11.x is not compatible with the socket.io/sails.io.js client SDK version you are using (0.9.0). Please see the v0.11 migration guide on http://sailsjs.org for more information.'
  • I dont have any problem with sails.io.js client, my problem is that i need make a request like socket.get(url) in an android app. Actually what I need is make a request to sails.js controller without using sails.io client helper methods, but from an application in android. Currently i use the socket.io-client.java link to issue events to the server – luis hernandez Feb 26 '15 at 02:11
  • hi Luis, any chance you could upload your code, I am struggling with sails and android as well, be nice to see something working! – dave Apr 15 '15 at 14:17
  • Hi dave, The answer of Khawer Zeshan is correct and allows you to manipulate sockets and communicate with android, you can use this [library](https://github.com/nkzawa/socket.io-client.java) to communicate with the server from your application, and in this [link](http://stackoverflow.com/questions/25081188/sending-socket-request-from-client-ios-android-to-sails-js-server) explain you how to communicate from android. I hope my answer will help :) – luis hernandez Apr 20 '15 at 02:57

3 Answers3

5

Just change your url to something like below

http://xxx.xxx.xxx.xxx:1234/?__sails_io_sdk_version=0.11.0
strings95
  • 661
  • 11
  • 26
0

I don't know about socket.get() request in android.

But I know that if your server is running v.0.11 of Sails, you need to upgrade your sails.io.js client to v0.11, as v0.9 is not compatible. It's explained in the migration guide, with instructions on how to upgrade: sails generate sails.io.js --force. All the details are in the link:

https://github.com/balderdashy/sails/blob/master/0.11-migration-guide.md#differences

Mayayushi
  • 81
  • 3
  • Hi, i dont have any problem with sails.io.js client, my problem is that i need make a request like socket.get(url) in an android app. Actually what I need is make a request to sails.js controller without using sails.io client helper methods, but from an application in android. Currently i use the socket.io-client.java [link](https://github.com/nkzawa/socket.io-client.java) to issue events to the server – luis hernandez Feb 26 '15 at 02:10
0

For some reason the version is not available in the SDK META DATA information. In the file node_modules\sails\node_modules\sails-hook-sockets\lib\parse-sdk-metadata.js there is a code which checks if version is not available in the meta data then assume the version is 0.9.0

if (!handshake.query[SDK_META_PARAMS.version]) {
    handshake.query[SDK_META_PARAMS.version] = '0.9.0';
}

So i changed 0.9.0 to 0.11.0 and voila! things are working.

Khawer Zeshan
  • 9,470
  • 6
  • 40
  • 63