免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1621 | 回复: 7

rpc 一个实在问题,请教。。。请指点迷经。。 [复制链接]

论坛徽章:
0
发表于 2009-04-20 11:23 |显示全部楼层
需要将下面的数据结构,从client 传送到server。并在server侧确认传输成功。

struct cell
{ int data;
   struct cell *left,*right;}
struct cell *a,*b,*c,*d;

a=malloc(size of (struct cell));
b=...
c=...
d=...

a->data=1;a->left=b;a->right=c;
b->data=2;b->left=NULL;b->right=d;
c->data=3;c->left=d;c->right=NULL;
d->data=4;d->left=NULL;d->right=NULL;

论坛徽章:
0
发表于 2009-04-20 11:30 |显示全部楼层

把我(自己都看不顺眼)的代码贴出来 瞧瞧

send.c

#include<stdio.h>
#include<stdlib.h>
#include<rpc/rpc.h>
#include "send.h"


main(argc,argv)
int argc;
char *argv[];
{
CLIENT *cl,*clnt_create();
char *server;
struct cell *nl;
int *result;
struct cell *a,*b,*c,*d;
a=malloc(sizeof(struct cell));
b=malloc(sizeof(struct cell));
c=malloc(sizeof(struct cell));
d=malloc(sizeof(struct cell));

a->data=1;
a->left=b;
a->right=c;

b->data=2;
b->left=NULL;
b->right=d;

c->data=3;
c->left=d;
c->right=NULL;

d->data=4;
d->left=NULL;
d->right=NULL;

server=argv[1];

cl=clnt_create(server,SENDPROG,SENDVERS,"tcp");
if(cl==NULL){
clnt_pcreateerror(server);
exit(1);
}
result=send_1(&a,cl);
if(*result==0)
   printf("error\n");
exit(0);
}

论坛徽章:
0
发表于 2009-04-20 11:34 |显示全部楼层

send_proc.c

#include<rpc/rpc.h>
#include<sys/types.h>
#include<stdio.h>
#include "send.h"

int * send_1(cell_a)
struct cell *cell_a;
{
static int result;
FILE *f;
f=fopen("/dev/console","w");
if(f==(FILE *)NULL){
   result=0;
   return(&result);
}
fprintf(f,"%s\n",cell_a->data);
struct cell *nl;

nl=malloc(sizeof(cell));

while((cell_a->left!=NULL)||(cell_a->right!=NULL))
{
nl->data=cell_a->data;
nl->left=cell_a->left;
nl->right=cell_a->right;
if(cell_a->left!=NULL)
{
send_1(cell_a->left);
}
if(cell_a->right!=NULL)
send_1(cell_a->right);
}
fclose(f);
result=1;
return(&result);
}

论坛徽章:
0
发表于 2009-04-20 11:36 |显示全部楼层

send.x

struct cell{
      int data;
      struct cell *left;
      struct cell *right;
};

program SENDPROG{
    version SENDVERS{
           int
           SEND(struct cell *)=1;
    }=1;
}=20000006;

论坛徽章:
0
发表于 2009-04-20 11:38 |显示全部楼层
gcc -o send_s send.c send_clnt.c send_xdr.c -lnsl
gcc -o send_r send_proc.c send_svc.c send_xdr.c -lnsl

send.r 在远端服务器(qq 服务器名)运行。。
本地执行 ./send_s qq
产生一CORE 文件。。。

论坛徽章:
0
发表于 2009-04-20 11:59 |显示全部楼层

回复 #1 wenqing_9115 的帖子

小弟觉得,与其看半天代码,不如跟一下core,一根不就知道是哪儿出错了。

论坛徽章:
0
发表于 2009-04-20 14:33 |显示全部楼层

回复 #1 wenqing_9115 的帖子

你把一个进程中的指针地址发送到另外的进程中, 貌似没什么用啊

论坛徽章:
0
发表于 2009-04-21 15:40 |显示全部楼层
这个 远程过程调用貌似只能用 指针传递。。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP