Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.24 KB | None | 0 0
  1. import java.util.Vector;
  2. import org.apache.xmlrpc.XmlRpcClient;
  3.  
  4. public class klientRPC {
  5.  
  6.     public static void main(String[] args) {
  7.         // TODO Auto-generated method stub
  8.         try {
  9.             XmlRpcClient srv = new
  10.                     XmlRpcClient("http://localhost:10004");
  11.             Vector<Integer> params = new Vector<Integer>();
  12.             params.addElement(new Integer(13));
  13.             params.addElement(new Integer(21));
  14.             Object result =
  15.                     srv.execute("mojserwer.echo", params);
  16.             int wynik = ((Integer) result).intValue();
  17.             System.out.println("Wynik dodawanka: " + wynik);
  18.            
  19.             AC cb = new AC();
  20.             Vector<Integer> params2 = new Vector<Integer>();
  21.             params2.addElement(new Integer(10000));
  22.             srv.executeAsync("mojserwer.asy", params2, cb);
  23.             System.out.println("Wywolano asynchronicznie");
  24.         } catch (Exception exception) {
  25.             System.err.println("Klient XML-RPC: " + exception);
  26.         }
  27.     }
  28.  
  29. }
  30.  
  31.  
  32. import org.apache.xmlrpc.WebServer;
  33.  
  34. public class serwerRPC {
  35.  
  36.     public static void main(String[] args) {
  37.         // TODO Auto-generated method stub
  38.         try {
  39.             System.out.println("Startuje serwer XML-RPC");
  40.             int port = 10004;
  41.             WebServer server = new WebServer(port);
  42.             //stworzenie obiektu klasy serwera i uruchomienie
  43.             server.addHandler("mojserwer", new serwerRPC());
  44.             server.start();
  45.             System.out.println("Serwer wystartowal pomyslnie.");
  46.             System.out.println("Nasluchuje na porcie: " + port);
  47.             System.out.println("Aby zatrzymac serwer nacisnij ctrl+c");
  48.         } catch (Exception exception) {
  49.             System.err.println("Serwer XML-RPC: " + exception);
  50.         }
  51.  
  52.     }
  53.    
  54.     public Integer echo(int x, int y) {
  55.         return new Integer(x+y);
  56.     }
  57.    
  58.     public int asy(int x) {
  59.         System.out.println("... wywolano asy - odliczam");
  60.         try {
  61.             Thread.sleep(x);
  62.         } catch(InterruptedException ex) {
  63.             ex.printStackTrace();
  64.             Thread.currentThread().interrupt();
  65.         }
  66.         System.out.println("... asy - koniec odliczania");
  67.         return(123);
  68.     }
  69. }
  70.  
  71.  
  72. import java.net.URL;
  73.  
  74. import org.apache.xmlrpc.AsyncCallback;
  75.  
  76. public class AC implements AsyncCallback {
  77.     public void handleResult(Object rezultat, URL url, String metoda) {
  78.         System.out.println("XD1: " + rezultat);
  79.     }
  80.    
  81.     public void handleError(Exception e, URL url, String metoda) {
  82.         System.out.println("XD2: " + e);
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement