Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.Vector;
- import org.apache.xmlrpc.XmlRpcClient;
- //public class KlientRPC {
- //
- // public static void main(String[] args) {
- //
- // try {
- // XmlRpcClient srv = new XmlRpcClient("http://192.168.43.63:1000");
- // Vector<Integer> params = new Vector<>();
- // params.addElement(13);
- // params.addElement(17);
- // Object result = srv.execute("MojSerwer.echo", params);
- //
- // int wynik = ((Integer) result).intValue();
- // System.out.println("Wynik = " + wynik);
- //
- // AC cb = new AC();
- // Vector<Integer> params2 = new Vector<>();
- // params2.addElement(1000);
- // srv.executeAsync("MojSerwer.execAsy", params2, cb);
- // System.out.println("Wywolano asynchronicznie");
- //
- // } catch (Exception exception) {
- // System.err.println("Klient XML-RPC: " + exception);
- // }
- // }
- //}
- public class KlientRPC {
- public static void main(String[] args) {
- try {
- Scanner sc = new Scanner(System.in);
- System.out.println("Podaj adres serwera (domyślnie http://localhost:10014):");
- String address = sc.next();
- XmlRpcClient srv = new XmlRpcClient(address);
- Vector<Integer> params = new Vector<>();
- String result = (String) srv.execute("mojserwer.show", params);
- System.out.println(result);
- int g = 0;
- while (g==0) {
- System.out.println("Podaj nazwę usługi:");
- String serviceName = sc.next();
- Vector<Object> params2 = new Vector<>();
- if (serviceName.equals("getValueAsy")) {
- System.out.println("Podaj funkcję trygonometryczną");
- params2.add(sc.next());
- System.out.println("Podaj kąt");
- params2.add(sc.nextInt());
- System.out.println("Podaj czas oczekiwania");
- params2.add(sc.nextInt());
- AC cb = new AC();
- srv.executeAsync("mojserwer.getValueAsy", params2, cb);
- System.out.println("Wywołano asynchronicznie");
- }
- else if (serviceName.equals("squareSum")) {
- System.out.println("Podaj pierwszą liczbę");
- params2.add(sc.nextDouble());
- System.out.println("Podaj drugą liczbę");
- params2.add(sc.nextDouble());
- Object result2 = srv.execute("mojserwer.squareSum", params2);
- System.out.println("Wynik:" + result2);
- }
- else if(serviceName.equals("isMultiplicity")) {
- System.out.println("Podaj pierwszą liczbę");
- params2.add(sc.nextInt());
- System.out.println("Podaj drugą liczbę");
- params2.add(sc.nextInt());
- Object result2 = srv.execute("mojserwer.isMultiplicity", params2);
- System.out.println("Wynik:" + result2);
- }
- else if(serviceName.equals("getLiczbyPierwszeAsy")) {
- System.out.println("Podaj dolny zakres: ");
- params2.add(sc.nextInt());
- System.out.println("Podaj górny zakres: ");
- params2.add(sc.nextInt());
- Object result2 = srv.execute("mojserwer.getLiczbyPierwszeAsy", params2);
- System.out.println("Wynik:" + result2);
- }
- else if(serviceName.equals("show")) {
- Object result2 = srv.execute("mojserwer.show", params2);
- System.out.println(result2);
- }
- else {
- System.out.println("Nie ma takiej usługi.");
- }
- }
- sc.close();
- } catch (Exception exception) {
- System.err.println("Klient XML-RPC: " + exception);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement