Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. SERWER:
  2. #include <fcntl.h>
  3. #include <stdio.h>
  4. #include <sys/stat.h>
  5. #include <unistd.h>
  6.  
  7. #define MAX_BUF 1024
  8. char buf[MAX_BUF];
  9. void czysc()
  10. {
  11. int i;
  12. for(i = 0; i < MAX_BUF; i++)
  13. {
  14. buf[i] = 0;
  15. }
  16. }
  17. int main()
  18. {
  19. int fd;
  20. char * myfifo = "/tmp/myfifo";
  21. /* open, read, and display the message from the FIFO */
  22. fd = open(myfifo, O_RDONLY);
  23. while(1)
  24. {
  25. read(fd, buf, MAX_BUF);
  26. printf("Received: %s\n", buf);
  27. czysc();
  28. }
  29. close(fd);
  30.  
  31. return 0;
  32. }
  33.  
  34.  
  35.  
  36. $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$44
  37. KLIENT
  38. $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  39. #include <fcntl.h>
  40. #include <sys/stat.h>
  41. #include <sys/types.h>
  42. #include <stdio.h>
  43. #include <stdlib.h>
  44. #include <unistd.h>
  45. #include <string.h>
  46. #define N 1024
  47. char string[N];
  48. int main()
  49. {
  50. int fd;
  51. char * myfifo = "/tmp/myfifo";
  52. umask(0);
  53. /* create the FIFO (named pipe) */
  54. mkfifo(myfifo, 0666);
  55. fd = open(myfifo, O_WRONLY);
  56. while(1)
  57. {
  58. sleep(1);
  59. printf("Podaj ciag znakow: ");
  60. scanf("%s", string);
  61. write(fd, string, strlen(string));
  62. }
  63. close(fd);
  64.  
  65. /* remove the FIFO */
  66. unlink(myfifo);
  67.  
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement