Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Vector;
- import org.apache.xmlrpc.XmlRpcClient;
- public class klientRPC {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- try {
- XmlRpcClient srv = new
- XmlRpcClient("http://localhost:10004");
- Vector<Integer> params = new Vector<Integer>();
- params.addElement(new Integer(13));
- params.addElement(new Integer(21));
- Object result =
- srv.execute("mojserwer.echo", params);
- int wynik = ((Integer) result).intValue();
- System.out.println("Wynik dodawanka: " + wynik);
- AC cb = new AC();
- Vector<Integer> params2 = new Vector<Integer>();
- params2.addElement(new Integer(10000));
- srv.executeAsync("mojserwer.asy", params2, cb);
- System.out.println("Wywolano asynchronicznie");
- } catch (Exception exception) {
- System.err.println("Klient XML-RPC: " + exception);
- }
- }
- }
- import org.apache.xmlrpc.WebServer;
- public class serwerRPC {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- try {
- System.out.println("Startuje serwer XML-RPC");
- int port = 10004;
- WebServer server = new WebServer(port);
- //stworzenie obiektu klasy serwera i uruchomienie
- server.addHandler("mojserwer", new serwerRPC());
- server.start();
- System.out.println("Serwer wystartowal pomyslnie.");
- System.out.println("Nasluchuje na porcie: " + port);
- System.out.println("Aby zatrzymac serwer nacisnij ctrl+c");
- } catch (Exception exception) {
- System.err.println("Serwer XML-RPC: " + exception);
- }
- }
- public Integer echo(int x, int y) {
- return new Integer(x+y);
- }
- public int asy(int x) {
- System.out.println("... wywolano asy - odliczam");
- try {
- Thread.sleep(x);
- } catch(InterruptedException ex) {
- ex.printStackTrace();
- Thread.currentThread().interrupt();
- }
- System.out.println("... asy - koniec odliczania");
- return(123);
- }
- }
- import java.net.URL;
- import org.apache.xmlrpc.AsyncCallback;
- public class AC implements AsyncCallback {
- public void handleResult(Object rezultat, URL url, String metoda) {
- System.out.println("XD1: " + rezultat);
- }
- public void handleError(Exception e, URL url, String metoda) {
- System.out.println("XD2: " + e);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement