From e8f1271f06b06b35468e9d5a1a522327c99a2427 Mon Sep 17 00:00:00 2001 From: Tinsae Date: Sun, 21 Dec 2025 21:30:45 +0100 Subject: [PATCH] task 2 may be done. --- week3_TinsaeGhilay/Task 2/README.md | 25 +++++++++++++++++++ .../Task 2/src/client/Client.java | 13 ++++++++-- .../Task 2/src/server/Server.java | 5 ++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/week3_TinsaeGhilay/Task 2/README.md b/week3_TinsaeGhilay/Task 2/README.md index e69de29..c6cc28c 100644 --- a/week3_TinsaeGhilay/Task 2/README.md +++ b/week3_TinsaeGhilay/Task 2/README.md @@ -0,0 +1,25 @@ +## Task 2 + +### Structure +*** +1. **lib:** .jar files downloaded from [apache](https://archive.apache.org/dist/ws/xmlrpc/binaries/). the downloaded file is extracted and the contents of the `lib` directory copied in here. +2. **out:** output binaries in packages `server` and `client` +3. **src:** source code in 2 packages `client` and `server` + +### How to run +*** +1. First we compile the code (in linux using the following command) + ```bash + # the "lib/*" tells jvm to include these libraries + javac -cp "lib/*" -d out $(find src -name "*.java") + ``` + +2. Then we start the server. again run the following command + ```bash + java -cp "out:lib/*" server.Server + ``` + +3. And finaly we run the client as such + ```bash + java -cp "out:lib/*" client.Client + ``` \ No newline at end of file diff --git a/week3_TinsaeGhilay/Task 2/src/client/Client.java b/week3_TinsaeGhilay/Task 2/src/client/Client.java index ecbd211..b72dcdd 100644 --- a/week3_TinsaeGhilay/Task 2/src/client/Client.java +++ b/week3_TinsaeGhilay/Task 2/src/client/Client.java @@ -18,6 +18,9 @@ import org.apache.xmlrpc.*; import org.apache.xmlrpc.client.XmlRpcClient; import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; +// logging +import org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory; + public class Client { private static String TAG = "Client"; @@ -25,15 +28,21 @@ public class Client { public static void main(String[] args) { try (Scanner scanner = new Scanner(System.in)) { + // create an XML-RPC client object with address to server @ localhost // URL can be any valid URL. the default port for XML-RPC is 80 // but here we use 8080 since 80 may need root privileges XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); - config.setServerURL(new URL("http://localhost:8080/RPC2")); - + config.setServerURL(URI.create("http://localhost:8080/RPC2").toURL()); XmlRpcClient client = new XmlRpcClient(); client.setConfig(config); + // Logging of XML-RPC messages between server and client + XmlRpcCommonsTransportFactory factory = new XmlRpcCommonsTransportFactory(client); + // enable logging + factory.setEnableLogging(true); + client.setTransportFactory(factory); + while (true) { // create parameters to be sent to server method in a vector // and populate it diff --git a/week3_TinsaeGhilay/Task 2/src/server/Server.java b/week3_TinsaeGhilay/Task 2/src/server/Server.java index b64ff3b..6f61774 100644 --- a/week3_TinsaeGhilay/Task 2/src/server/Server.java +++ b/week3_TinsaeGhilay/Task 2/src/server/Server.java @@ -14,6 +14,11 @@ import java.net.URL; import org.apache.xmlrpc.server.PropertyHandlerMapping; import org.apache.xmlrpc.server.XmlRpcServer; +// logging imports +import java.util.logging.ConsoleHandler; +import java.util.logging.Level; +import java.util.logging.Logger; + public class Server { private static String TAG = "Server";