中间件实验报告1

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

电子科技大学计算机学院标准实验报告(实验)课程名称:中间件技术(实验)项目名称:用Windows下的RPC客户端调用Linux上的文件服务器实现文件的基本操作电子科技大学研究生院电子科技大学实验报告学生姓名学号实验中所参与的工作完成所有工作一、实验目的:本实验的目的和任务是,用Windows下的RPC客户端调用Linux上的文件服务器实现文件的基本操作,让学生理解中间件的基本原理,并掌握进行RPC程序设计和开发的基本方法。二、实验内容:在Linux下完成RPC的开发,然后将客户端代码移植到Windows下编译运行,实现Windows下的RPC客户端调用Linux上的文件服务器实现文件的基本操作(openclosereadwrite);三、实验步骤:1.相关技术研究,学习RPC的总体架构和编程方法。2.在服务器端完成idl文件的编写,然后用rpcgen生成相关文件,修改生成的服务器端的代码NFileSystem_server.c,实现对文件的具体操作。通过makefile编译生成可执行文件。3.配置VC++6.0,寻找相关的库文件如oncrpc.sdk等,将Linux下rpcgen生成的客户端的代码NFileSystem_client.c,NFileSystem_clnt.c,NFileSystem_xdr.c和NFileSystem.h移植到windows下,进行编译测试。4.测试、总结,相关的测试报告四、总结及心得体会:在搭建Linux环境时由于使用ubuntu版本较高需要安装rpcbind来启动RPC服务。在把Linux下生成的客户端程序移植到windows编译的时候,发现还是有点麻烦的,需要下载oncrpc.sdk,将oncrpc.sdk\include目录下的文件拷到VC6自己的include目录下,比如我的虚拟机是C:\ProgramFiles\MicrosoftVisualStudio\VC98\Include,将oncrpc.sdk\win32lib目录下的pwrpc32.lib拷到VC6的lib目录下,我的是C:\ProgramFiles\MicrosoftVisualStudio\VC98\Lib,将xdr.c文件中的“registerint32_t*buf;”这一行删除,然后windows端才能进行RPC通信,经过这次试验,学习到了RPC程序设计的基本方法,受益匪浅。五、测试和截图测试环境:虚拟机Ubuntu/Linux作为服务器,ip地址是10.0.4.118。虚拟机WindowsXp作为客户端,采用Vc++6.0编译器。客户端访问服务器文件/home/wame100/test.txt,分别测试open,close,read,write.截图:图1客户端测试截图图2服务器测试截图六、附件关键代码NFileSystem.xconstMAXREADWORD=100;constMAXWRITEWORD=100;constMAXFILENUM=128;constMAXFILELEN=50;structopenfile{charfile_name[MAXFILELEN];intflag;};structreadpar{intfd;intsize;};structwriteword{intfd;charword_write[MAXWRITEWORD];};structreadword{charword_read[MAXREADWORD];intsize;};programNETWORK_FISYSTERM_PROG{versionNETWORK_FIFYFTEM_VER{intOPEN_FILE(structopenfile)=1;intCLOSE_FILE(int)=2;structreadwordREAD_FILE(structreadpar)=3;intWRITE_FILE(structwriteword)=4;}=1;}=0x30090939;改写的NFileSystem_server.c/**Thisissamplecodegeneratedbyrpcgen.*Theseareonlytemplatesandyoucanusethem*asaguidelinefordevelopingyourownfunctions.*/#includeNFileSystem.h#includefcntl.h#includestdio.h#includestring.hint*open_file_1_svc(structopenfile*argp,structsvc_req*rqstp){staticintresult;/**insertservercodehere*/result=open(argp-file_name,O_RDWR|O_APPEND);printf(rpc打开文件%sfd=%d\n,argp-file_name,result);return&result;}int*close_file_1_svc(int*argp,structsvc_req*rqstp){staticintresult;/**insertservercodehere*/result=close(*argp);printf(rpc关闭文件\n);return&result;}structreadword*read_file_1_svc(structreadpar*argp,structsvc_req*rqstp){staticstructreadwordresult;/**insertservercodehere*/result.size=read(argp-fd,result.word_read,argp-size);printf(rpc读取文件%d%dbytes\n,argp-fd,result.size);result.word_read[result.size]='\0';printf(文件内容%s\n,result.word_read);return&result;}int*write_file_1_svc(structwriteword*argp,structsvc_req*rqstp){staticintresult;/**insertservercodehere*/result=write(argp-fd,argp-word_write,strlen(argp-word_write));printf(rpc向文件中写入%dbytes写入内容:%s\n,strlen(argp-word_write),argp-word_write);return&result;}Windows客户端代码:/**Thisissamplecodegeneratedbyrpcgen.*Theseareonlytemplatesandyoucanusethem*asaguidelinefordevelopingyourownfunctions.*/#includeNFileSystem.h#pragmacomment(lib,pwrpc32.lib)voidnetwork_fisysterm_prog_1(char*host){CLIENT*clnt;int*result_1;structopenfileopen_file_1_arg;intclose_file_1_arg;structreadword*result_2;structreadparread_file_1_arg;int*result_3;structwritewordwrite_file_1_arg;int*result_4;//#ifndefDEBUGclnt=clnt_create(host,NETWORK_FISYSTERM_PROG,NETWORK_FIFYFTEM_VER,tcp);if(clnt==NULL){clnt_pcreateerror(host);exit(1);}//#endif/*DEBUG*/strncpy(open_file_1_arg.file_name,/home/wame100/test.txt,26);result_1=open_file_1(&open_file_1_arg,clnt);if(result_1==(int*)NULL){clnt_perror(clnt,callfailed);}else{printf(文件打开成功fd=%d\n,*result_1);}read_file_1_arg.fd=*result_1;read_file_1_arg.size=50;result_2=read_file_1(&read_file_1_arg,clnt);if(result_2==(structreadword*)NULL){clnt_perror(clnt,callfailed);}else{printf(文件大小%dbyte,读取文件内容:%s\n,result_2-size,result_2-word_read);}write_file_1_arg.fd=*result_1;strncpy(write_file_1_arg.word_write,201421060107wangmeng,40);result_3=write_file_1(&write_file_1_arg,clnt);if(result_3==(int*)NULL){clnt_perror(clnt,callfailed);}else{printf(文件写入成功\n);}close_file_1_arg=*result_1;result_4=close_file_1(&close_file_1_arg,clnt);if(result_4==(int*)NULL){clnt_perror(clnt,callfailed);}else{printf(文件关闭成功\n);}//#ifndefDEBUGclnt_destroy(clnt);//#endif/*DEBUG*/}intmain(intargc,char*argv[]){char*host;if(argc2){printf(usage:%sserver_host\n,argv[0]);exit(1);}host=argv[1];network_fisysterm_prog_1(host);exit(0);}

1 / 8
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功