2

我想开发一个可以与使用 Apache thrift 开发的服务器进行通信的 android 应用程序......

import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;

import android.app.Activity;


import android.os.Bundle;
import android.widget.Toast;

public class ThriftExampleActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        try
        {<br>   //this code is used to cretae an client
            TTransport transport = new TSocket("107.20.177.28", 8888);
            transport.open();
            TProtocol protocol = new  TBinaryProtocol(transport);
            Mainservice.Client client = new Mainservice.Client(protocol);
            //upto this line is common code for client need not to touch

            //below call any API using client object created above
            //like I have call add API which take some input and return output
            System.out.println(client);
           Getsearch g=new Getsearch();
          g.rows="5";
           g.text="india";
           g.page=Integer.toString(2);
           Toast.makeText(getBaseContext(), client.get_search(g).toString(), <br>Toast.LENGTH_LONG).show();
           System.out.println(client.get_search(g));
            //System.out.println("The Sum is: "+sum);

            //close client socket
            transport.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}
4

0 回答 0