task 2 may be done.

This commit is contained in:
2025-12-21 21:30:45 +01:00
parent 5141562548
commit e8f1271f06
3 changed files with 41 additions and 2 deletions

View File

@@ -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
```

View File

@@ -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

View File

@@ -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";