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. [转]VGA、QVGA、CIF、QCIF 。。。的含义

    转自:http://www.360doc.com/content/07/0329/15/494_419655.shtml 相信大家时常都听到手机支持 VGA 镜头.QVGA 屏幕显示.CIF 短片拍摄 ...

  2. python 正则表达式 demo

    1.匹配大小写和数字,并且大小写数字均要有,且字符串长度为6~20位 ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Z\d]{6,20}$ import repattern ...

  3. compass项目监控文件报 /usr/bin/env 找不到文件

    1 找到ruby执行文件目录 $ wherris ruby ruby: /usr/lib/ruby /home/rudy/.rbenv/shims/ruby 2 设置软链接 sudo ln -s /h ...

  4. 使用jQuery解析xml时command节点解析失败

    jQuery版本1.8.3 待解析的xml为: <message><user><command>Login</command></message& ...

  5. nyoj 68 三点顺序

    点击打开链接 三点顺序 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 现在给你不共线的三个点A,B,C的坐标,它们一定能组成一个三角形,现在让你判断A,B,C是顺时针给 ...

  6. 配置Tomcat数据源

    1.方式一:在server.xml中配置 1)tomcat安装路径下conf目录下的server.xml,在<GlobalNamingResources>和</GlobalNamin ...

  7. ubuntu实用技巧

    添加alias ~/.bash_alias文件: alias go="python /Users/xhat/Downloads/goagent/local/proxy.py" ~/ ...

  8. C#(Visual Studio) AssemblyInfo

    AssemblyInfo .NET Project的Properties文件夹下会自动生成一个AssemblyInfo.cs的文件,该文件包含的信息和项目->右键->属性->Appl ...

  9. linux下OpenCV的安装配置

    1 安装cmake及一些依赖库 sudo apt-get install cmake sudo apt-get install build-essential libgtk2.0-dev libavc ...

  10. 如何激活phpstorm | phpstorm的下载

    2016年7月14日 phpsotrm 推送2016.2 更新 phpstorm的下载地址 https://www.jetbrains.com/phpstorm/download/#section=w ...