Skip to content

Instantly share code, notes, and snippets.

@Sadamingh
Created March 23, 2021 03:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sadamingh/65749175a5b9e8fdd95d98e2e4904b7c to your computer and use it in GitHub Desktop.
Save Sadamingh/65749175a5b9e8fdd95d98e2e4904b7c to your computer and use it in GitHub Desktop.
#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;
}
#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