-
-
Save OlivierLaflamme/94bc2b18f449d738f1bd89d72efd8993 to your computer and use it in GitHub Desktop.
pipes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
client.c | |
#include <Windows.h> | |
#include <stdio.h> | |
#define MAX_SIZE 1024 | |
int main(int argc, char **argv) { | |
CHAR *remotePipeName = (CHAR*)GlobalAlloc(GPTR, MAX_SIZE); | |
DWORD dwWritten = 0; | |
snprintf(remotePipeName, MAX_SIZE, "\\\\.\\%s\\%s", argv[1], argv[2]); | |
printf("Connecting to %s\n", remotePipeName); | |
HANDLE hPipe = CreateFile(remotePipeName, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); | |
printf("hPipe 0x%p\n", hPipe); | |
WriteFile(hPipe, argv[3], strlen(argv[3]), &dwWritten, NULL); | |
CloseHandle(hPipe); | |
return 0; | |
} | |
============================================================================= | |
server.c | |
#include <Windows.h> | |
#include <stdio.h> | |
#define MAX_SIZE 1024 | |
int main() { | |
CHAR buffer[MAX_SIZE]; | |
DWORD dwRead = 0; | |
HANDLE hPipe = CreateNamedPipe("\\\\.\\pipe\\boschko", PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, PIPE_UNLIMITED_INSTANCES, MAX_SIZE, 0, 10000, NULL); | |
printf("hPipe 0x%p\n", hPipe); | |
ConnectNamedPipe(hPipe, NULL); | |
ReadFile(hPipe, buffer, MAX_SIZE, &dwRead, NULL); | |
printf("We got %d bytes\n", dwRead); | |
printf("Received: %s\n", buffer); | |
DisconnectNamedPipe(hPipe); | |
CloseHandle(hPipe); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment