I have a Socket server waiting for the clients send messages in a json format. I do not need to store the data into database, but for now, I would like to keep them in a hashtable. So, when the client sent a message the server will add it to the hashtable without losing the previous messages.
Here is the declaration of my hashtable:
private static Hashtable<Integer,String> table = new Hashtable<Integer,String>();
Here is the method that is called a message reach the server:
private void HashTable(String string){
//JsonArray questions = new JsonArray();
//questions = string;
//for(int i = 0; i < questions.length(); i++) {
//JsonObject question = questions.getJsonObject(i);
JSONObject jsonObj;
try {
jsonObj = new JSONObject(string);
int id = jsonObj.optInt("DeviceID", -1);
String name = jsonObj.toString();
table.put(id, name);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//}
}
The code above is not keeping the data from the previous messages. Could anybody give a hint?
thank you