Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3. import java.util.Vector;
  4.  
  5. import org.apache.xmlrpc.XmlRpcClient;
  6.  
  7. //public class KlientRPC {
  8. //
  9. // public static void main(String[] args) {
  10. //
  11. // try {
  12. // XmlRpcClient srv = new XmlRpcClient("http://192.168.43.63:1000");
  13. // Vector<Integer> params = new Vector<>();
  14. // params.addElement(13);
  15. // params.addElement(17);
  16. // Object result = srv.execute("MojSerwer.echo", params);
  17. //
  18. // int wynik = ((Integer) result).intValue();
  19. // System.out.println("Wynik = " + wynik);
  20. //
  21. // AC cb = new AC();
  22. // Vector<Integer> params2 = new Vector<>();
  23. // params2.addElement(1000);
  24. // srv.executeAsync("MojSerwer.execAsy", params2, cb);
  25. // System.out.println("Wywolano asynchronicznie");
  26. //
  27. // } catch (Exception exception) {
  28. // System.err.println("Klient XML-RPC: " + exception);
  29. // }
  30. // }
  31. //}
  32.  
  33.  
  34. public class KlientRPC {
  35.  
  36. public static void main(String[] args) {
  37. try {
  38. Scanner sc = new Scanner(System.in);
  39. System.out.println("Podaj adres serwera (domyślnie http://localhost:10014):");
  40. String address = sc.next();
  41. XmlRpcClient srv = new XmlRpcClient(address);
  42.  
  43. Vector<Integer> params = new Vector<>();
  44. String result = (String) srv.execute("mojserwer.show", params);
  45. System.out.println(result);
  46.  
  47. int g = 0;
  48. while (g==0) {
  49. System.out.println("Podaj nazwę usługi:");
  50. String serviceName = sc.next();
  51. Vector<Object> params2 = new Vector<>();
  52. if (serviceName.equals("getValueAsy")) {
  53. System.out.println("Podaj funkcję trygonometryczną");
  54. params2.add(sc.next());
  55. System.out.println("Podaj kąt");
  56. params2.add(sc.nextInt());
  57. System.out.println("Podaj czas oczekiwania");
  58. params2.add(sc.nextInt());
  59. AC cb = new AC();
  60. srv.executeAsync("mojserwer.getValueAsy", params2, cb);
  61. System.out.println("Wywołano asynchronicznie");
  62. }
  63. else if (serviceName.equals("squareSum")) {
  64. System.out.println("Podaj pierwszą liczbę");
  65. params2.add(sc.nextDouble());
  66. System.out.println("Podaj drugą liczbę");
  67. params2.add(sc.nextDouble());
  68. Object result2 = srv.execute("mojserwer.squareSum", params2);
  69. System.out.println("Wynik:" + result2);
  70. }
  71. else if(serviceName.equals("isMultiplicity")) {
  72. System.out.println("Podaj pierwszą liczbę");
  73. params2.add(sc.nextInt());
  74. System.out.println("Podaj drugą liczbę");
  75. params2.add(sc.nextInt());
  76. Object result2 = srv.execute("mojserwer.isMultiplicity", params2);
  77. System.out.println("Wynik:" + result2);
  78. }
  79. else if(serviceName.equals("getLiczbyPierwszeAsy")) {
  80. System.out.println("Podaj dolny zakres: ");
  81. params2.add(sc.nextInt());
  82. System.out.println("Podaj górny zakres: ");
  83. params2.add(sc.nextInt());
  84. Object result2 = srv.execute("mojserwer.getLiczbyPierwszeAsy", params2);
  85. System.out.println("Wynik:" + result2);
  86. }
  87. else if(serviceName.equals("show")) {
  88. Object result2 = srv.execute("mojserwer.show", params2);
  89. System.out.println(result2);
  90. }
  91.  
  92. else {
  93. System.out.println("Nie ma takiej usługi.");
  94. }
  95. }
  96.  
  97. sc.close();
  98.  
  99. } catch (Exception exception) {
  100. System.err.println("Klient XML-RPC: " + exception);
  101. }
  102.  
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement