免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1599 | 回复: 3

命名管道[已经解决] [复制链接]

论坛徽章:
0
发表于 2007-05-17 13:19 |显示全部楼层
Server 端代码
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>

#include <linux/stat.h>

#define FIFO_FILE "MYFIFO"

int main(void)
{
        FILE *fp;
        char readbuf[80];

        printf("Waiting message...\n");
        umask(0);
        mknod(FIFO_FILE, S_IFIFO|0666, 0);
        while(1)
        {
                fp = fopen(FIFO_FILE, "r");
                fgets(readbuf, 80, fp);
                printf("Receiveed string :%s", readbuf);
                fclose(fp);
                sleep(1);
        }

        return 0;

}


Client 端代码
#include <stdlib.h>
#include <stdio.h>

#define FIFO_FILE "MYFIFO"

int main(int argc, char *argv[])
{
        FILE *fp;
        if(argc != 2)
        {
                printf("Usage: fifoclient [string]\n");
                exit(1);
        }
        if((fp = fopen(FIFO_FILE, "w")) == NULL)
        {
                perror("fopen");
                exit(1);
        }
        fputs(argv[1], fp);
        fclose(fp);
        return 0;
}

为啥client端执行之后server端没有任何反应呢?

[ 本帖最后由 lnfxcf 于 2007-5-17 14:48 编辑 ]

论坛徽章:
0
发表于 2007-05-17 13:43 |显示全部楼层
是不是该用open read 之类的系统调用,我记得我写的时候都是用的这些系统调用

论坛徽章:
0
发表于 2007-05-17 14:31 |显示全部楼层
Buffer...

在 printf("Receiveed string :%s", readbuf); 后面加一句 fflush(stdout);

论坛徽章:
0
发表于 2007-05-17 14:48 |显示全部楼层
哦!非常感谢!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP