1、RPC通信模型

2、调用截图

服务器端

PC客户端:

Android客户端:

3、remotetea

jrpcgen.jar:生成Java源文件

oncrpc.jar:框架通信调用

portmap.jar:Windows调用

4、生成Java源文件

test.x

const MAXNAMELEN = 2048;
typedef string test_string<MAXNAMELEN>;
program TEST_RPC_FUNCTION_NUMBER
{
version TEST_RPC_FUNCTION_VERSION
{
mcps_string TEST_TEST(string) = 1;
mcps_string TEST_DO_PROCESS(string) = 2;
} = 1;
} = 0x20000001;

命令:java -jar jrpcgen test.x

生成的文件:

test.java

test_string.java

testClient.java(文件中的mcps_string改为test_string)

testServerStub.java(文件中的mcps_string改为test_string)

5、Server端:

引用:oncrpc.jar和4个Java文件

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException; import org.acplt.oncrpc.OncRpcException; public class Main extends testServerStub { public Main(InetAddress bindAddr, int port) throws OncRpcException,
IOException {
super(bindAddr, port);
// TODO Auto-generated constructor stub
} public test_string TEST_TEST_1(String arg1){ System.out.println("This is test function" + arg1);
return null;
} public test_string TEST_DO_PROCESS_1(String arg1){ System.out.println("Got msg from client " + arg1);
return null;
} /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try{ System.out.println("--Server Start--");
InetAddress address = null;
try{
//address = InetAddress.getLocalHost();
address = InetAddress.getByAddress(new byte[]{(byte)192, (byte)168, (byte)1, (byte)101});
System.out.println(address.toString());
}catch(UnknownHostException e){
System.out.println(e.getMessage());
} Main server = new Main(address, 2023);
System.out.println("Is server null? " + (server == null ? true : false));
server.run(); }catch(Exception e){ System.out.println(e.getMessage());
} } }

6、Client端

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException; import org.acplt.oncrpc.OncRpcException;
import org.acplt.oncrpc.OncRpcProtocols; public class Main extends testClient { public Main(InetAddress host, int port, int protocol)
throws OncRpcException, IOException {
super(host, port, protocol);
// TODO Auto-generated constructor stub
} /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub System.out.println("--Start Client--");
InetAddress address = null; try{
//address = InetAddress.getLocalHost();
address = InetAddress.getByAddress(new byte[]{(byte)192, (byte)168, (byte)1, (byte)101}); System.out.println(address.toString());
}catch(UnknownHostException e){
System.out.println(e.getMessage());
} try{
// Main client = new Main(address, 2023, OncRpcProtocols.ONCRPC_TCP);
// client.TEST_TEST_1("SSB Test2");
// client.close(); Main client = new Main(address, 2023, OncRpcProtocols.ONCRPC_TCP);
client.TEST_DO_PROCESS_1("SSB Test");
client.close(); }catch(OncRpcException e){
System.out.println(e.getMessage());
}catch(IOException e){
System.out.println(e.getMessage());
}
} }

7、Android端:

package com.fish.compass.util;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException; import org.acplt.oncrpc.OncRpcException;
import org.acplt.oncrpc.OncRpcProtocols; public class Main extends testClient { public Main(InetAddress host, int port, int protocol)
throws OncRpcException, IOException {
super(host, port, protocol);
} /**
* @param args
*/
public static String run() {
StringBuilder rtn = new StringBuilder();
rtn.append("--Start Client--"); InetAddress address = null;
try{
address = InetAddress.getByAddress(new byte[]{(byte)192, (byte)168, (byte)1, (byte)101});
rtn.append(address.toString());
}catch(UnknownHostException e){
rtn.append(e.getMessage());
} try{
Main client = new Main(address, 2023, OncRpcProtocols.ONCRPC_TCP);
client.TEST_DO_PROCESS_1("SSB phone Test");
client.close(); }catch(OncRpcException e){
rtn.append(e.getMessage());
}catch(IOException e){
rtn.append(e.getMessage());
} return rtn.toString();
} }

Activity

package com.fish.compass;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection; import com.fish.compass.util.Main; import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.graphics.Color;
import android.media.RingtoneManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast; public class MainActivity extends Activity { TextView m_TextView; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); Button m_OKButton = (Button) findViewById(R.id.m_OKButton);
m_TextView = (TextView) findViewById(R.id.m_MsgTextView); m_OKButton.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
Thread t = new Thread(new Runnable(){ @Override
public void run() {
getMsg();
} });
t.start(); }
}); } Handler m_Handler = new Handler(){
@Override
public void handleMessage(Message msg){
super.handleMessage(msg);
if(msg.what == 1){
m_TextView.setText(msg.obj.toString());
}
}
}; public void getMsg(){ StringBuilder sb = new StringBuilder(); try{ String msg = Main.run(); sb.append(msg); }catch(Exception ex){
sb.append(ex.getMessage());
} m_Handler.obtainMessage(1, sb.toString()).sendToTarget();
} }

源码下载:百度网盘

参考:

http://blog.csdn.net/jackliang55/article/details/7580563

RPC通信(Windows版、Android版)的更多相关文章

  1. Delphi For Android 开发笔记-附:如何Delphi中同时实现Windows、Android版的GetModuleFileName函数

    在Windows中开发DLL时,经常会需要获取当前DLL所在目录以便读取同目录下的其他文件,而目前Delphi在开发android时,其实没多大必要获取,因为整个工程只有一个so文件,而这个so文件也 ...

  2. SpringBoot2+Netty打造通俗简版RPC通信框架(升级版)

    背景         上篇文章我简单的介绍了自己打造的通俗简版RPC通信框架,这篇是对简版的增强~         如果大家对此项目还感兴趣的话,可到码云上瞄瞄:Netty-RPC         上 ...

  3. SpringBoot2+Netty打造通俗简版RPC通信框架

    2019-07-19:完成基本RPC通信! 2019-07-22:优化此框架,实现单一长连接! 2019-07-24:继续优化此框架:1.增加服务提供注解(带版本号),然后利用Spring框架的在启动 ...

  4. android电源“有毒”移动电源Android版的设计及其实现

    工作之余抽点时间出来写写博文,希望对新接触的朋友有帮助.今天在这里和大家一起学习一下android电源 报道http://www.cnbeta.com/articles/239726.htm称:安全研 ...

  5. React Native App设置&Android版发布

    React Native系列 <逻辑性最强的React Native环境搭建与调试> <ReactNative开发工具有这一篇足矣> <解决React Native un ...

  6. Windows 10正式版历代记:Version 和 Build 对应关系

    2017年10月中下旬,微软面向正式版用户推送了Windows 10创意者更新秋季版.这是自发布以来,Windows 10的第五个大版本. 在这篇文章中,我们来回顾一下Windows 10正式版的历史 ...

  7. Android版-微信APP支付

    首发地址: Android版-微信APP支付 欢迎留言.转发 微信极速开发系列文章(微信支付.授权获取用户信息等):点击这里 目录 1.注册账号.开发者认证 2.添加应用 3.申请微信支付 4.技术开 ...

  8. 凡信(超仿微信Android版)开源了,内有源码下载 -

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 凡信(超仿微信Android版)开源了,内有源码下载 - IM Geek开发者社区-移动 ...

  9. Windows 10正式版历代记:Version 1709、Build 16299都是什么鬼?

    Windows 10免费用!创意者更新秋季版激活秘籍 2017年10月中下旬,微软面向正式版用户推送了Windows 10创意者更新秋季版.这是自发布以来,Windows 10的第五个大版本. 在这篇 ...

  10. 【项目记录】-液化气配送app android版

    15年底参与过甲方呼叫中心平台开发.液化气配送app android版要求1个月开发完成.开发此项目以前我只有过一周android的开发经验.(与甲方签署过保密协议,遵循职业道德有些敏感信息不能写.) ...

随机推荐

  1. this web application instance has been stopped already解决办法

    重启tomcat的时候出错 Illegal access: this web application instance has been stopped already.  Could not loa ...

  2. js中如何操作json数据

    一.要想熟练的操作json数据,就先要了解json数据的结构,json有两种结构:对象和数组. 1.对象 一个对象以“{”开始,“}”结束.每个“名称”后跟一个“:”:“‘名称/值’ 对”之间使用“, ...

  3. 解决insmod: error inserting 'hello.ko': -1 Invalid module format

    编译自己的内核模块后,insmod出现error:error inserting 'hello.ko': -1 Invalid module format 出现这种情况的原因是因为Makefile种使 ...

  4. jquery怎么实现跨域的访问呢?与别人提供的接口连接

    下面这个例子你可以参考下 <script> $.ajax({ async:false, url: 'http://www.mysite.com/demo.do',  // 跨域URL ty ...

  5. 使用commons-codec包加密字符串(MD5,SHA1,BASE64)

    1. [代码]MD5 String str = "abc"; DigestUtils.md5Hex(str); //附.net生成MD5的方法,生成内容跟java一致: Strin ...

  6. esriSRProjCS2Type Constants

    ArcGIS Developer Help  (Geometry)   esriSRProjCS2Type Constants See Also esriSRProjCSType Constants ...

  7. [ACDream 1430]SETI 后缀数组

    题目链接:http://acdream.info/problem?pid=1430 题目大意:给你一个长度不超过10000的字符串,问你出现过两次或两次以上的不重叠的子串有多少个. 后缀数组计算出he ...

  8. 求链表中倒数第k个节点

    注意鲁棒性和算法效率的典型例题:(头文件省略) typedef struct node { int data; struct node* next; }ListNode; ListNode* Find ...

  9. Oracle 11gR2 Database UNDO表空间使用率居高不下-转载

    客户的数据库是Oracle Database 11.2.0.3.0 for AIX 6.1 64bit的单机数据库.客户查询DBA_FREE_SPACE发现UNDO表空间的使用率高达98%以上.客户的 ...

  10. JavaScript对象的创建之使用json格式定义

    json: javascript simple object notation. json就是js的对象,但是它省去了xml中的标签,而是通过{}来完成对象的说明. 定义对象 var person = ...