将android xmlrpc连接到java服务器

时间:2015-10-27 04:41:11

标签: java android xml-rpc

我用过这个库 android xml rpc  在Java服务器中调用“sum”函数,但它不起作用,我不能调用sum函数

这是我的android代码:(我在真实设备上运行)

XMLRPCClient client = new XMLRPCClient("http://192.168.1.57:8000/RPC2");
int sum = (Integer) client.call("sum", 2);

这是我的服务器代码:

public class JavaServer {

    private Integer sum = 0;

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        try{
            System.out.println("Attempting to start XML-RPC Server...");

            WebServer server = new WebServer(8000);

            XmlRpcServer xmlRpcServer = server.getXmlRpcServer();

            PropertyHandlerMapping phm = new PropertyHandlerMapping();
            phm.addHandler("sample", JavaServer.class);
            xmlRpcServer.setHandlerMapping(phm);

            server.start();

            System.out.println("Started successfully.");
            System.out.println("Accepting requests. (Halt program to stop.)");
        } catch(Exception ex){
            System.err.println("JavaServer: " + ex);
        }
    }

    public Integer sum(int x){
        sum += x;
        System.out.println("sum: " + sum);
        return sum;
    }
}

0 个答案:

没有答案