-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessageClient.c
49 lines (40 loc) · 1.13 KB
/
messageClient.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
//Defining buffer limit for inter-process comms
#define LIMIT 50
int main (int argc, char *argv[]) {
int fd, fdRead;
char ch;
char buffer[LIMIT];
//Error handling
while ((fd = open("../FIFO", O_WRONLY)) == -1) {
fprintf(stderr, "trying to connect\n");
sleep(1);
}
//Error handling
while((fdRead = open("../FIFO1", O_RDONLY)) == -1) {
fprintf(stderr, "Read Error.\n");
exit(1);
}
printf("Connected: type in data to be sent\n");
/*Reading from the FIFO. Using scanf with %*c argument to read
from the stream but not further store it in the args*/
while (scanf("%c%*c", &ch) != -1) {
write(fd, &ch, 1);
//Reading from FIFO1, for server's acknowledgement
read(fdRead, buffer, LIMIT);
//Printing char-by-char
for (int i = 0; i < strlen(buffer); i++) {
printf("%c", buffer[i]);
}
}
//closing FIFOs
close(fd);
close(fdRead);
return 0;
}