Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <windows.h>
- const char nome[]="\\\\.\\pipe\\pippo";
- void ConnectToClient(HANDLE hpipe){
- int i;DWORD dwWrite;
- BOOL bRet;FILE *f;
- f = fopen("testo.txt","r");
- if(ConnectNamedPipe(hpipe,NULL)==0)
- {printf("Errore di connessione al client: \n");}
- while (feof(f) == 0)
- {
- char messaggio [100];
- fgets(messaggio,100,f);
- bRet = WriteFile(hpipe,messaggio,sizeof(messaggio),&dwWrite,NULL);
- if(bRet==FALSE)
- {printf("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)
- {printf("Errore apertura pipe: %d\n",GetLastError());}
- ConnectToClient(hpipe);
- CloseHandle(hpipe);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement