Results 1 to 6 of 6
Hello everyone.
i am trying to make a simple chat application using fifos. This is what i tried:
PROCESS 1:
Code:
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
int main(void)
{
...
- 08-10-2010 #1Just Joined!
- Join Date
- Aug 2008
- Posts
- 5
Simple Chat application
Hello everyone.
i am trying to make a simple chat application using fifos. This is what i tried:
PROCESS 1:
Code:#include <stdio.h> #include <fcntl.h> #include <string.h> int main(void) { int fd1, fd2; char buf[100]; if( ((fd1 = open("fifo1", O_WRONLY)) < 0) || ((fd2 = open("fifo2", O_RDONLY)) < 0) ) { perror("Error"); } else { printf("\nBegin chat"); for(;;) { scanf("%s", buf); write(fd1, buf, strlen(buf) + 1); /* read chat reply */ for(;;) { if( read(fd2, buf, 1) <= 0 ) break; printf("%c", buf[0]); } } } close(fd1); close(fd2); return 0; }
PROCESS 2:
Code:#include <stdio.h> #include <fcntl.h> #include <string.h> int main(void) { int fd1, fd2; char buf[100]; if( ((fd1 = open("fifo1", O_RDONLY)) < 0) || ((fd2 = open("fifo2", O_WRONLY)) < 0) ) { perror("Error"); } else { printf("\nBegin chat"); for(;;) { scanf("%s", buf); write(fd2, buf, strlen(buf) + 1); /* read chat reply from client */ for(;;) { if( read(fd1, buf, 1) <= 0 ) break; printf("%c", buf[0]); } } } close(fd1); close(fd2); return 0; }
- 08-10-2010 #2Just Joined!
- Join Date
- Aug 2008
- Posts
- 5
But it is not working. im not able to get the changing data in either of the terminals.
im running these processes from different terminals. But it did not work
Can anyone please explain what changes i need to make?
Thanks in advance.
- 08-10-2010 #3Just Joined!
- Join Date
- Jul 2010
- Posts
- 53
have a look at write and talk commands - there are several things that do this between terminals - if that's your objective.
or is this just a programming exercise for you?
- 08-11-2010 #4Just Joined!
- Join Date
- Aug 2008
- Posts
- 5
Thanks for the reply. Yes it is just as a practice. Can you please tell me where im going wrong?
- 08-11-2010 #5Just Joined!
- Join Date
- Feb 2006
- Posts
- 13
You have to create the fifo first, use mknod to create the fifo.
Hope this helps.
- 08-11-2010 #6Just Joined!
- Join Date
- Aug 2008
- Posts
- 5
Yes i did..But i used mkfifo.Then i added "w" permission for all.The problem is, im not able get simultaneous replies in the two terminals..ANy idea what the problem is?
Thanks.


Reply With Quote