WINDOWS簡單郵槽程式設計

2021-06-03 11:46:43 字數 988 閱讀 6698

//服務端

#include "stdafx.h"

#include #include int _tmain(int argc, _tchar* argv)

; dword numberofbytesread=0;

if((mailslot = createmailslot(l"\\\\.\\mailslot\\myslot", 0, mailslot_wait_forever, null))

== invalid_handle_value)

while(readfile(mailslot, buffer, 256, &numberofbytesread, null) != 0)

system("pause");

return 0;

}

//客戶端

#include "stdafx.h"

#include #include int _tmain(int argc, _tchar* argv)

; wcscpy(servername, l"\\\\.\\mailslot\\myslot");

if((mailslot = createfile(servername, generic_write, file_share_read, null, open_existing,

file_attribute_normal, null))==invalid_handle_value)

if(writefile(mailslot, "this is a test", sizeof("this is a test") , &byteswritten, null) == 0)

printf("wrote %d bytes\n", byteswritten);

closehandle(mailslot);

system("pause");

return 0;

}

Windows網路程式設計基礎(1) 郵槽

2018 9 6 12 21 04 郵槽的使用 預備知識 createfile,readfile的使用 關鍵的函式 createmailslot 如果建立失敗 返回乙個無效的控制代碼值invilid handle value 用乙個有效的控制代碼建立了郵槽之後,便可開始資料的實際讀取。伺服器是唯一能...

郵槽的應用

郵槽 在網路上程序通訊為單向方式 onmailslotrecv 接收端即為伺服器端 char buf 100 dword dwread if readfile hmailslot,buf,100,dwread,null closehandle hmailslot return buf 在客戶端要知道...

郵槽mailslot通訊學習

相關出處 windows網路程式設計技術 第3章 郵槽 郵槽為輕量級程序間通訊應用。郵槽使用方便。郵槽使用的缺點有如下兩點。郵槽服務端 ipcserver.cpp檔案如下。include stdafx.h include include int tmain int argc,tchar argv r...