RAKNET RPC3 Plugins - Remote Procedure Calls With Boost 远程功能调用
来源:互联网 发布:ibm 云计算 编辑:程序博客网 时间:2024/05/16 05:31
1. 基于Boost
Boost是什么? Boost库是一个可移植、提供源代码的C++库,作为标准库的后备,是C++标准化进程的发动机之一
Linux如何安装Boost? 不需要安装,只需解压并且在自己的开发环境配置头文件路径即可快速使用。
最新Boost 1.53.0下载地址:https://sourceforge.net/projects/boost/files/boost/1.53.0/
2. RakNet RPC3 Plugin Interface
RPC3是RakNet提供的一个实现远程功能函数调用服务的插件,使用它可以方便的让终端像调用本地函数一样调用远程服务器所注册对外公开的函数。
RakNet RPC3的插件实现位于RakNet开发包的 DependentExtensions/RPC3/,所以编译时需要把该目录下的RPC3.cpp一同编译。
3. RPC3 Demo
#include "MessageIdentifiers.h"#include "RakPeerInterface.h"#include "RakNetTypes.h"#include "Kbhit.h"#include "Gets.h"#include "RakSleep.h"#include "RPC3/RPC3.h"void RPCFun(RakNet::RakString rakString, RakNet::RPC3 *rpcFromNetwork){ printf("Called from %s", rpcFromNetwork->GetLastSenderAddress().ToString()); printf(", Message: %s\n", rakString.C_String());}RakNet::RPC3 *rpc3Inst;int main(void){rpc3Inst = new RakNet::RPC3;RPC3_REGISTER_FUNCTION(rpc3Inst, RPCFun); // 需要启动的终端类型,服务端或者客户端bool isServer = false;char message[2048];printf("(S)erver or (C)lient?: ");Gets(message, sizeof(message));if (message[0]=='s' || message[0]=='S') isServer=true;RakNet::RakPeerInterface *rakPeer = RakNet::RakPeerInterface::GetInstance();if (isServer){RakNet::SocketDescriptor socketDescriptor(50000,0);socketDescriptor.socketFamily=AF_INET; // Only IPV4 supports broadcast on 255.255.255.255rakPeer->Startup(10, &socketDescriptor, 1);rakPeer->SetMaximumIncomingConnections(10);printf("Server started.\n\n");}else{RakNet::SocketDescriptor socketDescriptor(0,0);socketDescriptor.socketFamily=AF_INET; // Only IPV4 supports broadcast on 255.255.255.255rakPeer->Startup(1, &socketDescriptor, 1);// 客户端自行查找网络内的服务器rakPeer->Ping( "255.255.255.255", 50000, true, 0 );printf("Client started.\n\n");}// 为PeerInterface注册插件rakPeer->AttachPlugin(rpc3Inst);// 一定得接收数据,PluginInterface2是基于数据包发送的哦~// Receive是RPC3插件实现的数据接口函数,必须执行才能使其发生作用。否则RPC是无法执行的哦~RakNet::Packet *p;while (1){ if (kbhit()) { Gets(message, sizeof(message)); puts(message); // 把输入的文字使用远程调用的方式传给RPCFun rpc3Inst->CallC("RPCFun", message, rpc3Inst); } for (p=rakPeer->Receive(); p; rakPeer->DeallocatePacket(p), p=rakPeer->Receive()) {switch (p->data[0]){// 使用自动连接方式必须由此段代码,代表发现服务器case ID_UNCONNECTED_PONG:rakPeer->Connect(p->systemAddress.ToString(false),p->systemAddress.GetPort(),0,0,0);break;// 该状态小时已经连接case ID_CONNECTION_REQUEST_ACCEPTED:printf("ID_CONNECTION_REQUEST_ACCEPTED\n");break;// RPC3出现错误case ID_RPC_REMOTE_ERROR:printf("Function: %s", p->data+2);break;}}RakSleep(0);}// 用完关闭是一种美德!rakPeer->Shutdown(100,0);RakNet::RakPeerInterface::DestroyInstance(rakPeer);delete rpc3Inst;return 1;}
4. Demo效果
- 左边是服务端,右边是客户端
- 服务器端使用的端口是 50000,客户端使用随机端口41968
您可以修改并重新发布本文,如果您能留下本文的参考连结,万分谢谢!
如果您对本文存在疑问,欢迎留言或者直接对本文评论,我会在看到的第一时间回复您。
- RAKNET RPC3 Plugins - Remote Procedure Calls With Boost 远程功能调用
- Remote Procedure Calls (RPC)
- Remote Procedure Calls (RPC)
- implementing remote procedure calls读书笔记
- 远程过程调用 Remote Procedure Call
- RakNet RPC3 & NetworkIDManager
- RakNet的远程功能调用(RPC)服务端
- RakNet的远程功能调用(RPC)客户端
- RPC(Remote Procedure Call 远程过程调用)
- RPC:远程过程调用协议(Remote Procedure Call protocol)
- RPC:远程过程调用协议(Remote Procedure Call protocol)
- 远程过程调用协议(Remote Procedure Call Protocol,RPC)
- 远程过程调用(Remote Procedure Call,RPC)
- rabbitmq(六)RPC(Remote procedure call,远程过程调用)
- 杂文-远程过程调用协议RPC(Remote Procedure Call Protocol)
- RPC(Remote Procedure Call Protocol远程过程调用)
- Making Remote Procedure Calls (GWT RPC) 学习笔记
- android in practice_Making remote procedure calls(GoodShares project)
- android adb启动失败问题 adb server is out of date. killing... ADB server didn't ACK * failed to start daem
- android pbap client
- linux异常系列:Can't connect to X11 window
- Nagios的进程监控及eventhandler之实战
- Java 通过URL获取网站Html源代码
- RAKNET RPC3 Plugins - Remote Procedure Calls With Boost 远程功能调用
- SD卡升级——SDIO IAP实验
- 《深入理解JAVA虚拟机》--第二章 Java内存溢出异常
- linux异常系列:Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
- opencart页面打开效率优化
- linux双网卡双网关,不同IP段的设置
- JS中setTimeout()的用法详解
- 只复制表结构不复制内容
- Maven使用中的常见问题整理