Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <windows.h>
- const char nome[] = R"(\\.\pipe\pippo)";
- void ConnectToClient(HANDLE hpipe) {
- DWORD dwWrite;
- BOOL bRet;
- std::ifstream file("testo.txt");
- if (!file.is_open()) {
- std::cerr << "File inesistente. Uscita.\n";
- exit(-1);
- }
- if (ConnectNamedPipe(hpipe, NULL) == 0) {
- std::cerr << "Errore di connessione al client.\n";
- }
- while (!file.eof()) {
- char messaggio[100];
- file.getline(messaggio, 100);
- bRet = WriteFile(hpipe, messaggio, sizeof(messaggio), &dwWrite, NULL);
- if (bRet == FALSE) {
- std::cerr << "Errore di scrittura nella pipe.\n";
- }
- }
- Sleep(5000);
- DisconnectNamedPipe(hpipe);
- }
- int main(int argc, char* argv[]) {
- HANDLE hpipe;
- hpipe = CreateNamedPipe(nome, PIPE_ACCESS_OUTBOUND | FILE_FLAG_WRITE_THROUGH,
- PIPE_TYPE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES,
- 512, 512, 1000, NULL);
- if (hpipe == INVALID_HANDLE_VALUE) {
- std::cerr << "Errore apertura pipe: " << GetLastError() << "\n";
- }
- ConnectToClient(hpipe);
- CloseHandle(hpipe);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement