




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、學(xué)生姓名:張鵬學(xué)號: 150705040實(shí)驗(yàn)地點(diǎn):數(shù)計(jì)學(xué)院407 實(shí)驗(yàn)室實(shí)驗(yàn)課時(shí): 3 學(xué)時(shí)實(shí)驗(yàn)器材:計(jì)算機(jī)課程名稱:計(jì)算機(jī)操作系統(tǒng)實(shí)驗(yàn)名稱:2.4 實(shí)驗(yàn)四:使用命名管道實(shí)現(xiàn)進(jìn)程通信一、實(shí)驗(yàn)?zāi)康?、進(jìn)一步掌握windows 系統(tǒng)環(huán)境下進(jìn)程通信機(jī)制。2、熟悉進(jìn)程通信api二、實(shí)驗(yàn)環(huán)境及工具windows 7操作系統(tǒng), vc6三、實(shí)驗(yàn)內(nèi)容使用 windows 系統(tǒng)提供的命名管道完成兩個(gè)進(jìn)程之間的通信,要求能正確使用創(chuàng)建命名管道createnamepipe()、連接命名管道connectnamepipe()、拆除命名管道的連接disconnectnamepipe ()、連接服務(wù)器已建立的命名管道ca
2、llnamepipe ()、等待命名管道waitnamepipe ()等 api.四、實(shí)驗(yàn)步驟服務(wù)端/ 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;五、實(shí)驗(yàn)結(jié)論window
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 兒童心理學(xué)在托管教育中的應(yīng)用
- 養(yǎng)生主題NFT數(shù)字藏品行業(yè)案例研究
- 中國快遞物流行業(yè)信用體系發(fā)展路徑研究
- 小學(xué)英語聽說訓(xùn)練方法探討
- IT支持工程師的職業(yè)發(fā)展及市場分析
- 汽車后市場服務(wù)創(chuàng)新與發(fā)展趨勢研究報(bào)告
- 對標(biāo)管理在加氣站安全中的實(shí)踐應(yīng)用
- 幼兒夏季游玩活動(dòng)方案
- 庫倫活動(dòng)跨年活動(dòng)方案
- 幼兒園班級素養(yǎng)活動(dòng)方案
- 夏季防暑降溫安全培訓(xùn)知識
- 肯德基市場細(xì)分分析
- 語文核心素養(yǎng)的培育智慧樹知到期末考試答案2024年
- MOOC 區(qū)塊鏈技術(shù)與應(yīng)用-西南交通大學(xué) 中國大學(xué)慕課答案
- 九三學(xué)社申請入社人員簡歷表
- 7.2 理解父母學(xué)會(huì)感恩(高效教案)-【中職專用】中職思想政治《心理健康與職業(yè)生涯》(高教版2023·基礎(chǔ)模塊)
- 高級護(hù)理實(shí)踐智慧樹知到期末考試答案2024年
- 食品安全肉類
- 配電運(yùn)維工作培訓(xùn)課件
- 2024年醫(yī)學(xué)高級職稱-胸心外科學(xué)(醫(yī)學(xué)高級)筆試歷年真題薈萃含答案
- 印刷采購服務(wù)整體供貨實(shí)施方案
評論
0/150
提交評論