import org.json.*;
import java.io.File;
import java.util.logging.*;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
/**
* Dispatches requests received via MessageIO, sends responses back
}
break;
+ case "hostname":
+ try {
+ String hostname = InetAddress.getLocalHost().getHostName();
+ response.put("content", hostname);
+ } catch (UnknownHostException e) {
+ response.put("status", 500);
+ response.put("message", "Cannot determine hostname " + e);
+ }
+ break;
+
default:
response.put("status", 404);
response.put("message", "Action not found: " + action);
pause();
+ // get the hostname
+ obj = new JSONObject();
+ obj.put("msgid", msgid++);
+ obj.put("clientid", clientid);
+ obj.put("origin", origin);
+ obj.put("action", "hostname");
+ io.sendMessage(obj);
+
+ pause();
+
+
/*
// Printing tests