惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
Security Latest
Security Latest
Simon Willison's Weblog
Simon Willison's Weblog
O
OpenAI News
GbyAI
GbyAI
L
LINUX DO - 最新话题
A
Arctic Wolf
T
Tor Project blog
G
GRAHAM CLULEY
I
InfoQ
博客园_首页
IT之家
IT之家
The Register - Security
The Register - Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
K
Kaspersky official blog
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
U
Unit 42
PCI Perspectives
PCI Perspectives
量子位
P
Palo Alto Networks Blog
S
Securelist
T
Troy Hunt's Blog
博客园 - 【当耐特】
Recorded Future
Recorded Future
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
Engineering at Meta
Engineering at Meta
T
The Blog of Author Tim Ferriss
博客园 - 聂微东
罗磊的独立博客
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
NISL@THU
NISL@THU
C
Cisco Blogs
T
Threatpost
有赞技术团队
有赞技术团队
Forbes - Security
Forbes - Security
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
T
The Exploit Database - CXSecurity.com
Cloudbric
Cloudbric
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
C
Cyber Attacks, Cyber Crime and Cyber Security

博客园 - longbigfish

部署(https证书) https证书问题(本地) 参数更新 Ubuntu 24安装Neo4j详细教程 protect 紧急 手机 刷脏页的两种模式 python中的多线程陷阱与pytorch分布式执行机制 git之复合指令和submodule mpi编程 cifs远程挂载 使用脚本进入一个命令行控制台,并预设执行的命令列表 cifs挂载远程文件出现 No such device or address错误 longtable 跨越多个页面时,如何在跨页时自动断行并加上横线及去掉页眉 matplotlib中文显示-微软雅黑 latex编译过程-关于嵌入所有字体 python做图笔记 linux启动全过程 连接并同步windows下的git仓库 反向ssh
rpc编程示例
longbigfish · 2022-01-19 · via 博客园 - longbigfish

参考 http://www.cems.uwe.ac.uk/~irjohnso/coursenotes/uqc109/rpcworksheet.pdf

一  定义服务器

/* remtime.x
rpc protocol spec for remote time worksheet */
const MAXSTRLEN = 80; /* max length of string */
typedef string datestr<MAXSTRLEN>; /* typedef for our ret. val.*/
program REMTIMEPROG {

version REMTIMEVERS {
datestr GETDATESTR() = 1;
} = 1;
} = 0x20650609;

使用 rpcgen remtime.x 生成服务器代码

remtime.h  remtime_svc.c  remtime_xdr.c

二  服务代码比如get_data.c

#include <rpc/rpc.h>
#include <time.h>
#include "remtime.h"
datestr *getdatestr_1_svc(void *x, struct svc_req *y)
{
static char buf[MAXSTRLEN];
static char *cp;
static datestr *dp;
time_t secs;
secs = time(NULL);
strcpy(buf,ctime(&secs));
cp = buf;
dp = &cp;
return(dp);
}

三 编译服务器

cc  remtime_svc.c  remtime_xdr.c get_data.c -o server

四 启动服务器

./server

如果发现 错误 

Cannot register service: RPC: Unable to receive; errno = Connection refused
unable to register (REMTIMEPROG, REMTIMEVERS, udp).

是 rpcinfo 没有装。 安装后就可以启动。 启动后用 rpcinfo  可以看到服务。

五。客户端程序  client.c

#include <stdio.h>
#include <rpc/rpc.h>
#include "remtime.h"
#define SERVER "localhost"
int main(void)
{
CLIENT *client; /* client handle - required */
datestr *resstring; /* pointer to a datestr to hold
result */
client = clnt_create(SERVER, REMTIMEPROG, REMTIMEVERS, "tcp");
/* create a client handle to the specified server, program, version
using the specified protocol */


if (client == NULL)
{
printf("Cannot connect to server\n");
clnt_pcreateerror(SERVER);
/* find out why - prints to stdout */
exit(1);
}
resstring = getdatestr_1(NULL, client);
/* as our function receives no arguments our first
argument is a pointer to void, the second a pointer
to the client handle we wish to use We should really
error check the return! */
printf("%s",*resstring);
return(0);
}

编译 cc -o client remtime_xdr.c remtime_clnt.c remclient.c

启动客户端 ./client 就可以看到打印日期  

./client
Wed Jan 19 01:56:13 2022

------

这里我们客户端和服务器在同一个节点,所以用 localhost连接服务器。可以在另一个节点上编译client,对应地server地址改为server所在节点的ip。

需要把 remtime_xdr.c remtime_clnt.c  remtime.h 一起拷贝过去编译 client。