RPC编程

RPC(Remote Procedure Call)允许客户端程序调用远程服务器上的过程。本文详细介绍了RPC的开发过程,包括定义client和server接口的*.x文件,开发server端和client端程序,以及编译和运行。RPC开发主要包括编写接口定义文件,编译接口文件,开发server.c和client.c,最后编译运行程序。
摘要由CSDN通过智能技术生成

RPC编程

.概述

一般的程序只能在本地编译执行,主程序和被调程序也是本地调用关系。RemoteProcedureCallsRPC)可以实现远程调用,客户端程序可以调用远端服务器的过程,服务器中的过程执行操作,将执行结果返回给客户端。

.RPC开发过程

RPC开发一共三步:

第一.定义clientserver交互接口,即*.x文件。

第二.开发client.c客户端程序。

第三.开发server.c服务端程序


以下面这个本地调用程序为例,讲述如何进行RPC开发。

/*client1.c*/
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
long bin_date(void);
char *str_date(long bintime);

int main(int argc, char *argv[]){
        long lresult;   /*return from bin_date*/
        char *sresult;  /*return from str_date*/
        if(argc!=1){
                fprintf(stderr,"usage:%s\n",argv[0]);
                exit(1);
        }
        /*call the procedure bin_date*/
        lresult=bin_date();
        printf("time is %ld\n",lresult);
        /*convert the result to a date string*/
        sresult=str_date(lresult);
        printf("date is %s",sresult);
        exit(0);
}

/*return system date as # seconds since Jan 1 1970 0:00, in binary formate*/
long bin_date(void){
        long timeval;
        long time(); /*unix time function, returns time*/

        timeval=time((long *)0);
        return timeval;
}

/*str_date convert a binary time into a date sting, return the date string*/
char * str_date(long bintime){
        char *ptr;
        char *ctime();/*unix library funciton that dose the work*/

        ptr=ctime(&bintime);
        return ptr;
}

以上所以在本地运行程序,下面想通过RPC在远端服务器上调用上面两个函数。

1.交互协议接口

1.1定义clientserver接口,*.x文件

一个远程调用过程由三个要素决定:程序号(

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值