版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、學(xué)生姓名:張鵬學(xué)號(hào): 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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 家政服務(wù)禮儀培訓(xùn)
- 家政服務(wù)員培訓(xùn)課件
- 花店店長(zhǎng)年終總結(jié)
- 培訓(xùn)教師普通話課件
- 2025年網(wǎng)絡(luò)安全防護(hù)與應(yīng)急響應(yīng)培訓(xùn)
- 急性失代償性心力衰竭管理的研究進(jìn)展2026
- 分析儀器安全培訓(xùn)心得
- 2025 小學(xué)一年級(jí)數(shù)學(xué)下冊(cè)左右相對(duì)性(鏡面)辨析課件
- 2025 小學(xué)一年級(jí)數(shù)學(xué)下冊(cè)帶小括號(hào)計(jì)算入門課件
- RFID原理與實(shí)踐 課件 1.1.1 條碼識(shí)別
- 計(jì)算機(jī)視覺(jué)PPT完整全套教學(xué)課件
- 高三英語(yǔ)閱讀理解:文章標(biāo)題型
- 《鄉(xiāng)土中國(guó)》 《無(wú)訟》課件
- GB/T 9870.1-2006硫化橡膠或熱塑性橡膠動(dòng)態(tài)性能的測(cè)定第1部分:通則
- GB/T 4675.1-1984焊接性試驗(yàn)斜Y型坡口焊接裂紋試驗(yàn)方法
- GB/T 1687.3-2016硫化橡膠在屈撓試驗(yàn)中溫升和耐疲勞性能的測(cè)定第3部分:壓縮屈撓試驗(yàn)(恒應(yīng)變型)
- FZ/T 73009-2021山羊絨針織品
- 資產(chǎn)評(píng)估收費(fèi)管理辦法(2023)2914
- 消防安全應(yīng)急預(yù)案及架構(gòu)圖
- 重大經(jīng)濟(jì)建設(shè)項(xiàng)目的稅收管理與服務(wù)
- 稽核培訓(xùn)ppt課件
評(píng)論
0/150
提交評(píng)論