Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SERWER:
- #include <fcntl.h>
- #include <stdio.h>
- #include <sys/stat.h>
- #include <unistd.h>
- #define MAX_BUF 1024
- char buf[MAX_BUF];
- void czysc()
- {
- int i;
- for(i = 0; i < MAX_BUF; i++)
- {
- buf[i] = 0;
- }
- }
- int main()
- {
- int fd;
- char * myfifo = "/tmp/myfifo";
- /* open, read, and display the message from the FIFO */
- fd = open(myfifo, O_RDONLY);
- while(1)
- {
- read(fd, buf, MAX_BUF);
- printf("Received: %s\n", buf);
- czysc();
- }
- close(fd);
- return 0;
- }
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$44
- KLIENT
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
- #include <fcntl.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <string.h>
- #define N 1024
- char string[N];
- int main()
- {
- int fd;
- char * myfifo = "/tmp/myfifo";
- umask(0);
- /* create the FIFO (named pipe) */
- mkfifo(myfifo, 0666);
- fd = open(myfifo, O_WRONLY);
- while(1)
- {
- sleep(1);
- printf("Podaj ciag znakow: ");
- scanf("%s", string);
- write(fd, string, strlen(string));
- }
- close(fd);
- /* remove the FIFO */
- unlink(myfifo);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement