I use this library (https://github.com/socketio/socket.io-client-java) to connect my Android application with my Sails socket.io.
Here is the code I use:
final Socket socket = IO.socket(Constants.LOCAL_URL+"?__sails_io_sdk_version=0.11.0");
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener()
{
@Override
public void call(Object... args)
{
JSONObject obj1 = new JSONObject();
try {
obj1.put("url","/rest/room");
} catch (JSONException e) {
e.printStackTrace();
}
socket.emit("get", obj1, new Ack() {
@Override
public void call(Object... args) {
Log.e("test", "GET");
}
});
Log.e("test", "CONNECT");
}
}).on("room", new Emitter.Listener()
{
@Override
public void call(Object... args)
{
Log.e("test", "ROOM");
}
});
But I have a 403 cause URL need an authentication. So how can I modify socket headers to put the Cookie
and keep the session between sockets and web services?