-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPipe_Server.c
More file actions
52 lines (51 loc) · 2.56 KB
/
Copy pathPipe_Server.c
File metadata and controls
52 lines (51 loc) · 2.56 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
// ------------------------------------------------------------------------------------------------
// B. Lang, OS
// ------------------------------------------------------------------------------------------------
#include <windows.h>
#include<stdio.h>
int main(void) {
HANDLE Pipe_C2VHD;
HANDLE Pipe_VHD2C;
char buffer[1024];
DWORD dwRead;
DWORD dwWrite;
printf("Pipe_Server\r\n");
Pipe_C2VHD = CreateNamedPipe(TEXT("\\\\.\\pipe\\PipeA"),
PIPE_ACCESS_OUTBOUND, // 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);
Pipe_VHD2C = CreateNamedPipe(TEXT("\\\\.\\pipe\\PipeB"),
PIPE_ACCESS_INBOUND, //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 ( (Pipe_C2VHD != INVALID_HANDLE_VALUE) && (Pipe_VHD2C != INVALID_HANDLE_VALUE) ) {
BOOL ret;
ret = ConnectNamedPipe(Pipe_C2VHD, NULL);
ret = ConnectNamedPipe(Pipe_VHD2C, NULL);
printf("starting\r\n");
{ int i;
char* values[] = {"0000 0\r\n\0", "0001 0\r\n\0", "0010 0\r\n\0", "0011 0\r\n\0",
"0100 0\r\n\0", "0101 0\r\n\0", "0110 0\r\n\0", "0111 0\r\n\0",
"1000 0\r\n\0", "1001 0\r\n\0", "1010 0\r\n\0", "1011 0\r\n\0",
"1100 0\r\n\0", "1101 0\r\n\0", "1110 0\r\n\0", "1111 1\r\n\0",NULL };
for(i=0;values[++i]!=NULL;) {
strcpy(buffer,values[i]);
if (WriteFile(Pipe_C2VHD, buffer, strlen(buffer), &dwWrite, NULL) == FALSE){ printf("write error"); break; }
if (ReadFile (Pipe_VHD2C, buffer, sizeof(buffer), &dwRead, NULL) == FALSE){ printf("read error"); break; }
buffer[dwRead] = '\0'; // add terminating zero
printf("%s", buffer); // process received data
}
}
}
DisconnectNamedPipe(Pipe_VHD2C);
DisconnectNamedPipe(Pipe_C2VHD);
return 0;
}