XML-RPC - java client vs php server

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

XML-RPC - java client vs php server

Postby miscialo » Sat Jan 16, 2010 4:42 pm

i have this java class. this class do a xml-rpc and send to the server page php 2 integers...
the server sums them and send back the result...
how i can trasform this for android???

Code: Select all
import java.util.*;
import helma.xmlrpc.*;

public class JavaClient {

    // The location of our server.
    private final static String server_url =
        "http://127.0.0.1/test/xmlrpc.php";

    public static void main (String [] args) {
        try {

            // Create an object to represent our server.
            XmlRpcClient server = new XmlRpcClient(server_url);

            // Build our parameter list.
            Vector params = new Vector();
            params.addElement(new Integer(45));
            params.addElement(new Integer(70));

            // Call the server, and get our result.
            Hashtable result =
                (Hashtable) server.execute("operation", params);
            int sum = ((Integer) result.get("sum")).intValue();
           

            // Print out our result.
            System.out.println("sum: " + Integer.toString(sum));

        } catch (XmlRpcException exception) {
            System.err.println("JavaClient: XML-RPC Fault #" +
                               Integer.toString(exception.code) + ": " +
                               exception.toString());
        } catch (Exception exception) {
            System.err.println("JavaClient: " + exception.toString());
        }
    }
}



i attach the library to import into the project...
Attachments
lib.zip
(904.83 KiB) Downloaded 29 times
Last edited by miscialo on Sat Jan 16, 2010 5:07 pm, edited 4 times in total.
miscialo
Freshman
Freshman
 
Posts: 8
Joined: Thu Jan 14, 2010 12:26 am

Top

Postby miscialo » Sat Jan 16, 2010 4:43 pm

this is the server page


Code: Select all
<?php
include 'xmlrpc.inc';
include 'xmlrpcs.inc';

function calc ($params) {

    // Parse our parameters.
    $xval = $params->getParam(0);
    $x = $xval->scalarval();
    $yval = $params->getParam(1);
    $y = $yval->scalarval();

    // Build our response.
    $struct = array('sum' => new xmlrpcval($x + $y, 'int'));
    return new xmlrpcresp(new xmlrpcval($struct, 'struct'));
}

new xmlrpc_server(array('operation' =>
                        array('function' => 'calc')));
?>
Attachments
xmlrpc.inc.zip
(41.02 KiB) Downloaded 31 times
miscialo
Freshman
Freshman
 
Posts: 8
Joined: Thu Jan 14, 2010 12:26 am

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 6 guests