클라이언트
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | int main() { HANDLE hPipe; unsigned char buffer[1024]; DWORD dwRead; /* hPipe = CreateNamedPipe(TEXT("\\\\.\\pipe\\Foo"), PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, // FILE_FLAG_FIRST_PIPE_INSTANCE is not needed but forces CreateNamedPipe(..) to fail if the pipe already exists... 1, 1024 * 16, 1024 * 16, NMPWAIT_USE_DEFAULT_WAIT, NULL); if (hPipe == INVALID_HANDLE_VALUE) co_s("handle error!"); */ hPipe = ::CreateFileA((c::p)"\\\\.\\pipe\\Foo", GENERIC_READ | GENERIC_WRITE, 0, nil, OPEN_EXISTING, 0, nil); if (hPipe == INVALID_HANDLE_VALUE) co_s("handle error!"); while (hPipe != INVALID_HANDLE_VALUE) { while (ReadFile(hPipe, buffer, sizeof(buffer) - 1, &dwRead, NULL) != FALSE) { /* add terminating zero */ //buffer[dwRead] = '\0'; /* do something with data in buffer */ co_s(s_yHdr(buffer)); //bytes to header and rawdata } } return (0); } | cs |
서버:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | int main() { hnd::t hPipe; unsigned long dwWritten; y::p data; headRaw_cP(data, "hello python..!", 16); activate_cpPipe(hPipe, "\\\\.\\pipe\\Foo", 1024); if (hPipe != INVALID_HANDLE_VALUE) { co_s("waiting for client.."); ::ConnectNamedPipe(hPipe, 0); writ_pipe(hPipe,data , 16); CloseHandle(hPipe); } return (0); } | cs |
참고:https://stackoverflow.com/questions/26561604/create-named-pipe-c-windows
'IPC(Pipe, Shared Mem)' 카테고리의 다른 글
c/python ipc 구현 블로그 (0) | 2019.01.31 |
---|---|
python 헤더 정의 (0) | 2019.01.31 |
python windows pipe server and client 예제 (0) | 2019.01.31 |
단일 프로세스 에서의 MMF write and read 예제 (0) | 2019.01.27 |
Windows API를 통해 심플한 MMF(Memory Mapped File) 구현 (0) | 2019.01.26 |