I am having trouble sending a JSONArray through socket.io in JAVA.
With the function below i am trying to authorize the user with his username and token.
public static void authorize()
{
HashMap<String, String> user = Database.getUser();
JSONArray req = new JSONArray();
try {
JSONObject reqObj = new JSONObject();
reqObj.put("username", user.get("username"));
req.put( reqObj );
reqObj = new JSONObject();
reqObj.put("usertoken", user.get("usertoken"));
req.put( reqObj );
} catch (JSONException e) {
e.printStackTrace();
}
Log.d("WebsocketFunctions", "Authorize: " + req.toString());
Socket.emit("authorize", req);
}
This is the Log.d("WebsocketFunctions") output:
Authorize: [{"username":"admin"},{"usertoken":"45345980983450983"}]
But on my node server i only get:
debug - websocket writing 1:: {username : 'admin'}
What i need is not only the username, but also the usertoken. Somehow the usertoken is not send to the server.
This is my node authorize function:
authorize: function(socket, data)
{
console.log('Authorize');
console.log(data);
},