task 2 may be done.
This commit is contained in:
@@ -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
|
||||||
|
```
|
||||||
@@ -18,6 +18,9 @@ import org.apache.xmlrpc.*;
|
|||||||
import org.apache.xmlrpc.client.XmlRpcClient;
|
import org.apache.xmlrpc.client.XmlRpcClient;
|
||||||
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
|
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
|
||||||
|
|
||||||
|
// logging
|
||||||
|
import org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory;
|
||||||
|
|
||||||
public class Client {
|
public class Client {
|
||||||
|
|
||||||
private static String TAG = "Client";
|
private static String TAG = "Client";
|
||||||
@@ -25,15 +28,21 @@ public class Client {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
try (Scanner scanner = new Scanner(System.in)) {
|
try (Scanner scanner = new Scanner(System.in)) {
|
||||||
|
|
||||||
// create an XML-RPC client object with address to server @ localhost
|
// 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
|
// 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
|
// but here we use 8080 since 80 may need root privileges
|
||||||
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
|
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();
|
XmlRpcClient client = new XmlRpcClient();
|
||||||
client.setConfig(config);
|
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) {
|
while (true) {
|
||||||
// create parameters to be sent to server method in a vector
|
// create parameters to be sent to server method in a vector
|
||||||
// and populate it
|
// and populate it
|
||||||
|
|||||||
@@ -14,6 +14,11 @@ import java.net.URL;
|
|||||||
import org.apache.xmlrpc.server.PropertyHandlerMapping;
|
import org.apache.xmlrpc.server.PropertyHandlerMapping;
|
||||||
import org.apache.xmlrpc.server.XmlRpcServer;
|
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 {
|
public class Server {
|
||||||
|
|
||||||
private static String TAG = "Server";
|
private static String TAG = "Server";
|
||||||
|
|||||||
Reference in New Issue
Block a user