Created
March 23, 2021 03:58
-
-
Save Sadamingh/65749175a5b9e8fdd95d98e2e4904b7c to your computer and use it in GitHub Desktop.
This file contains 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
#include <stdio.h> | |
#include <string.h> | |
#include <fcntl.h> | |
#include <sys/stat.h> | |
#include <sys/types.h> | |
#include <unistd.h> | |
#define FIFO_FILE "/tmp/myfifo" | |
int main() | |
{ | |
int fd; | |
char str[80]; | |
char *data; | |
mkfifo(FIFO_FILE, DEFFILEMODE); | |
printf("Named pipe established! ============== \n"); | |
fd = open(FIFO_FILE, O_RDONLY); | |
read(fd, str, 80); | |
printf("Server: %s", str); | |
close(fd); | |
fd = open(FIFO_FILE, O_WRONLY); | |
data = "Hello Server\n"; | |
printf("Client: send %s\n", data); | |
write(fd, data, strlen(data)+1); | |
close(fd); | |
return 0; | |
} |
This file contains 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
#include <stdio.h> | |
#include <string.h> | |
#include <fcntl.h> | |
#include <sys/stat.h> | |
#include <sys/types.h> | |
#include <unistd.h> | |
#define FIFO_FILE "/tmp/myfifo" | |
#define CONN_OK "Connected!\n" | |
int main() | |
{ | |
int fd; | |
char data[80]; | |
mkfifo(FIFO_FILE, DEFFILEMODE); | |
printf("Named pipe established! ============== \n"); | |
fd = open(FIFO_FILE, O_WRONLY); | |
printf("Server: send %s", CONN_OK); | |
write(fd, CONN_OK, strlen(CONN_OK)+1); | |
close(fd); | |
fd = open(FIFO_FILE, O_RDONLY); | |
read(fd,data, sizeof(data)); | |
printf("Client: %s\n", data); | |
close(fd); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment