Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <wait.h>
- #include <string.h>
- #define FIFO_FILE_1 "/tmp/client_to_server_fifo"
- #define FIFO_FILE_2 "/tmp/server_to_client_fifo"
- int main()
- {
- system("clear");
- int client_to_server;
- int server_to_client;
- char str[140];
- printf("Input message to server: ");
- scanf("%139[^\r\n]", str);
- /* write str to the FIFO */
- client_to_server = open(FIFO_FILE_1, O_WRONLY);
- server_to_client = open(FIFO_FILE_2, O_RDONLY);
- if(write(client_to_server, str, sizeof(str)) < 0){
- perror("Write:");//print error
- exit(-1);
- }
- if(read(server_to_client,str,sizeof(str)) < 0){
- perror("Read:"); //error check
- exit(-1);
- }
- printf("\n...received from the server: %s\n\n\n",str);
- close(client_to_server);
- close(server_to_client);
- /* remove the FIFO */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement