linux管道双工聊天
来源:互联网 发布:netbeans怎么编写java 编辑:程序博客网 时间:2024/05/11 16:51
A
#include "stdio.h"#include "pthread.h"#include "string.h"#include <fcntl.h>char fileout[20] = "fio.pipe";char fileint[20] = "fii.pipe";int r;int fd1; int fd2;int p1=0; int flag=0; char putbuff[256];char getbuff[256];void thread(){while(1){ //发送printf("清输入:");scanf("%s",putbuff);write(fd1,putbuff,strlen(putbuff)+1);};}int main(){r = mkfifo(fileint,0666);r = mkfifo(fileout,0666);fd1 = open(fileout,O_RDWR);fd2 = open(fileint,O_RDWR);pthread_t th;pthread_create(&th,NULL,(void *)thread,NULL);//线程创建while(1){ r = read(fd2,getbuff,sizeof(getbuff)-1); if(r > 0){getbuff[r] = 0;printf("\n对方说:%s \n",getbuff);}}pthread(th,NULL); //线程结束return 0;}
B
#include "stdio.h"#include "pthread.h"#include "string.h"#include <fcntl.h>char fileout[20] = "fio.pipe";char fileint[20] = "fii.pipe";int r;int fd1; int fd2;int p1=0; int flag=0; char putbuff[256];char getbuff[256];void thread(){while(1){ //发送printf("清输入:");scanf("%s",putbuff);write(fd2,putbuff,strlen(putbuff)+1);};}int main(){r = mkfifo(fileint,0666);r = mkfifo(fileout,0666);fd1 = open(fileout,O_RDWR);fd2 = open(fileint,O_RDWR);pthread_t th;pthread_create(&th,NULL,(void *)thread,NULL);//线程创建while(1){ r = read(fd1,getbuff,sizeof(getbuff)-1); if(r > 0){getbuff[r] = 0;printf("\n对方说:%s \n",getbuff);}}pthread(th,NULL); //线程结束return 0;}
0 0
- linux管道双工聊天
- linux管道通信 半双工通信
- 如何才能在linux下建立全双工管道。
- linux进程间通信-匿名半双工管道
- linux进程间通信-匿名半双工管道
- 全双工管道
- 管道 pipe 半双工/全双工
- Linux进程间通信的几种方法-半双工管道,命名管道,消息队列
- Linux进程间通信的几种方法-半双工管道,命名管道,消息队列
- 管道通信(半双工)
- python实现半双工聊天
- python实现半双工聊天
- FIFO管道/命名管道(半双工)
- Linux下用管道实现进程全双工通信的代码
- 基于Linux的SOCKET编程之TCP半双工Client-Server聊天程序
- 基于Linux的Socket编程之TCP全双工Server-Client聊天程序
- 基于Linux的SOCKET编程之TCP半双工Client-Server聊天程序
- 基于Linux的Socket编程之TCP全双工Server-Client聊天程序
- < meta http-equiv = "X-UA-Compatible" content = "IE=edge,chrome=1" />
- rxjava2的Observable使用方法(Observable不支持背压)
- 垃圾回收算法之 标记-清除算法
- 六类布线VS光纤布线
- Ubuntu Server系统获取和禁用root权限
- linux管道双工聊天
- hibernate 入门学习 Demo
- ofo共享单车和摩拜单车背后的物联网技术分析
- String中的subString() Java方法
- java-InputStream与OutputStream类型
- 各个缩写的含义
- Lecture 11: Debugging
- linux网络协议栈内核分析
- 物体变大变小