Reputation:
in javascript and node.js i can send data to server when connect like this
var s = io('http://216.157.91.131:8080/', { query: "foo=bar" });
s.connect();
var c = io.connect('http://216.157.91.131:8080/', { query: "foo=bar" });
and in server i can get the data like this
var io = require('socket.io')(server);
io.use(function(socket, next) {
var handshakeData = socket.request;
console.log("middleware:", handshakeData._query['foo']);
});
now in android how can i do same thing ? iam use
com.github.nkzawa:socket.io-client:0.4.2
for android and its code like this
IO.socket(host);
} catch (URISyntaxException e) {
e.printStackTrace();
}
client.on("id", messageHandler.onId);
client.connect();
now if i add some data with connection like javscript its show to me error
JSONObject id = new JSONObject();
id.put("user_id", 51);
IO.socket(host,id);
error message its
cannot reslove method 'socket(java.lang.string,org.json.JSONObject)'
Upvotes: 0
Views: 2452
Reputation:
i found sloution
IO.Options opts = new IO.Options();
opts.query = "auth_token=" + yourDataValue;
Socket socket = IO.socket("http://localhost", opts);
and u can get it by
var io = require('socket.io')(server);
io.use(function(socket, next) {
var handshakeData = socket.request;
var data = handshakeData._query['auth_token'];
});
Upvotes: 5