




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、学生姓名:张鹏学号: 150705040实验地点:数计学院407 实验室实验课时: 3 学时实验器材:计算机课程名称:计算机操作系统实验名称:2.4 实验四:使用命名管道实现进程通信一、实验目的1、进一步掌握windows 系统环境下进程通信机制。2、熟悉进程通信api二、实验环境及工具windows 7操作系统, vc6三、实验内容使用 windows 系统提供的命名管道完成两个进程之间的通信,要求能正确使用创建命名管道createnamepipe()、连接命名管道connectnamepipe()、拆除命名管道的连接disconnectnamepipe ()、连接服务器已建立的命名管道ca
2、llnamepipe ()、等待命名管道waitnamepipe ()等 api.四、实验步骤服务端/ pipeserver.cpp : defines the entry point for the console application./#include stdafx.h#include pipeserver.h#ifdef _debug#define new debug_new#undef this_filestatic char this_file = _file_;#endif/ the one and only application objectcwinapp theapp;u
3、sing namespace std;int _tmain(int argc, tchar* argv, tchar* envp)int nretcode = 0;int err;bool rc;handle hpipehandle1;char lpname=.pipemypipe;char inbuffer50=;char outbuffer50=;dword bytesread,byteswrite;hpipehandle1=createnamedpipe(lpctstr)lpname,pipe_access_duplex|file_flag_overlapped|write_dac, p
4、ipe_type_message|pipe_readmode_byte|pipe_w ait, 1,20,30,nmpwait_use_default_wait, (lpsecurity_a ttributes)null);if(hpipehandle1=inv alid_handle_value)|(hpipehandle1=null)err=getlasterror();printf(server pipe creat fail!err=%dn,err);exit(1);else printf(server pipe creat success!n);while(1)rc=connectn
5、amedpipe(hpipehandle1,(lpoverlapped)null);if(rc=0)err=getlasterror();printf(server pipe connect fail err=%dn,err);exit(2);else printf(server pipe connect successn);strcpy(inbuffer,);strcpy(outbuffer,);rc=readfile(hpipehandle1,inbuffer,sizeof(inbuffer),&bytesread,(lpoverlapped)null);if(rc=0&bytesread
6、=0)err=getlasterror();printf(server read pipe fail err=%dn,err);exit(3);elseprintf(server read pipe success!nda ta from client is=%sn,inbuffer);rc=strcmp(inbuffer,end);if(rc=0) printf(server write pipe fail!n);else printf(server write pipe success!n);disconnectnamedpipe(hpipehandle1);rc=strcmp(outbu
7、ffer,end);if(rc=0)break;printf(now server be end!n);closehandle(hpipehandle1);/*/ initialize mfc and print and error on failureif (!afxwininit(:getmodulehandle(null), null, :getcommandline(), 0)/ todo: change error code to suit your needscerr _t(fatal error: mfc initialization failed) endl;nretcode
8、= 1;else/ todo: code your applications behavior here. cstring strhello; strhello.loadstring(ids_hello);cout (lpctstr)strhello endl;*/return nretcode;客户端/pipeclient.cpp:definestheentrypointfortheconsoleapplication./#include#includestdafx.hpipeclient.h#ifdef#define#undefstatic_debugnewdebug_newthis_fi
9、lecharthis_file=_file_;#endif/theoneandonlyapplicationobjectcwinapptheapp;usingnamespace std;int_tmain(intargc,tchar* argv,tchar* envp)bool rc=0;charlpname=.pipemypipe;charinbuffer50=;charoutbuffer50=;dwordbytesread;intnretcode= 0;interr=0;while(1)strcpy(inbuffer,);strcpy(outbuffer,);printf(inputdat
10、aplease!n);scanf(%s,inbuffer);rc=strcmp(inbuffer,end);/initializemfcandprintand error on failureif(rc=0)rc=callnamedpipe(lpname,inbuffer,sizeof(inbuffer),outbuffer,sizeof(ou tbuffer),&bytesread,nmpwait_use_default_wait);break;rc=waitnamedpipe(lpname,nmpwait_wait_forever); if(rc=0)err=getlasterror();
11、printf(waitpipefail!err=%dn,err);exit(1);elseprintf(waitpipesuccess!n);rc=callnamedpipe(lpname,inbuffer,sizeof(inbuffer),outbuffer,sizeof(outbuffer),&bytesread,nmpwait_use_default_wait);rc=strcmp(outbuffer,end);if(rc=0)break;if(rc=0)err=getlasterror();printf(pipecallfail!err=%dn,err);exit(1);elseprintf(pipecallsuccess!ndatafrom server is %sn,outbuffer);printf(nowclienttobe end!n);returnnretcode;五、实验结论window
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 围产期心理护理
- 胃肠外科护理业务查房
- 2025至2031年中国液封式水表行业投资前景及策略咨询研究报告
- 2025至2031年中国棕色口服液瓶行业投资前景及策略咨询研究报告
- 2025至2031年中国方形靠垫行业投资前景及策略咨询研究报告
- 游戏竞赛企业制定与实施新质生产力项目商业计划书
- 2025至2031年中国太阳能路灯控制器行业投资前景及策略咨询研究报告
- 制造业基地行业跨境出海项目商业计划书
- 环保阅读材料企业制定与实施新质生产力项目商业计划书
- 2025至2031年中国喷胶软棉行业投资前景及策略咨询研究报告
- GB/T 4223-2004废钢铁
- GB/T 36148.1-2018船舶与海上技术海上环境保护围油栏第1部分:设计要求
- GB/T 16741-1997双面涂覆聚氯乙烯阻燃防水布、篷布
- GB 2811-1989安全帽
- 端子压接规范标准
- 新版《药品管理法》解读课件
- 东南大学附属中大医院ECMO操作记录单
- 环杭州湾地区发展战略规划研究
- 拟投入本项目的主要施工设备表
- 湖北省环境监测专业服务暂时行收费重点标准
- 纯碱MSDS报告化学品安全技术说明书
评论
0/150
提交评论