/* fifo server*/
#include
#include
#include
#inlcude
#include
define FIFO_SER "/tmp/fifo"
int main(int argc,char* argv[])
{
int fd;
int iRet;
int n;
char buf[]="hi,i came from server";
iRet = mkfifo(FIFO_SER,O_CREAT|O_EXCL);
if((iRet < 0)&&(errno != EEXIST))
{
perror("mkfifo");
return -1;
}
fd = open(FIFO_SER,O_WRONLY,0);
if(fd < 0)
{
perror("open");
return -1;
}
n = write(fd,buf,sizeof(buf));
if(n < 0)
{
perror("write");
return -1;
}
close(fd);
}
/*fifo client*/
#include
#include
#include
#inlcude
#include
#define FIFO_SER "/tmp/fifo"
#define BUF_LEN 1024
int main(int argc,char* argv[])
{
int fd;
int n;
int iRet;
char buf[BUF_LEN]
iRet = mkfifo(FIFO_SER,O_CREAT|O_EXCL);
if((iRet < 0)&&(errno != EEXIST))
{
perror("mkfifo");
return -1;
}
fd = open(FIFO_SER,O_RDONLY,0);
if(fd < 0)
{
perror("open");
return -1;
}
n = read(fd,buf,sizeof(buf));
if(n < 0)
{
perror("read");
return -1;
}
printf("recv:%s\n",buf);
return 0;
}