Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1612011
  • 博文数量: 245
  • 博客积分: 10378
  • 博客等级: 上将
  • 技术积分: 2571
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-27 08:19
文章分类

全部博文(245)

文章存档

2013年(4)

2012年(8)

2011年(13)

2010年(68)

2009年(152)

分类: LINUX

2009-03-27 08:41:10

本地聊天小程序:
  • 使用命名管道实现聊天功能
  • 基本功能是基于半双工模式
  • 主要是为了联系命名管道的使用


//发送端程序,接收端不写了,基本差不多,就是练练手

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>

int main(void)
{
    pid_t pid;  
    int fp,fp_rec;
    char buf[30];
    if( (mkfifo("fifo1",O_CREAT))<0 )
    {
        perror("mkfifo error");
        exit(1);
    }
/*
    if( (fp=open("fifo1",O_RDONLY))<0)
    {
        perror("open error");
        exit(1);
    } */

    if( (fp_rec=open("fifo1",O_WRONLY))<0 )
    {
        perror("open error");
        exit(1);
    }
    while(1)
    {
        printf("\nsova:");
        fgets(buf,30,stdin);    
        write(fp_rec,buf,30);
    
/*    printf("\npetter say:");
        read(fp,buf,30);        */

    }
    return 0;
}


阅读(909) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~