双管道实现进程数据通信
2009-04-02 23:29
531 查看
我用的服务器端程序如下:
#include "cliser.h"
#include<fcntl.h>
int main(int argc,char *argv[])
{
int res,client_fifo_fd;
char *temp_data_ptr;
int read_res;
mkfifo(SERVER_FIFO_NAME,0777);
res = open(SERVER_FIFO_NAME,O_RDONLY);
if(res == -1)
{
printf("open read server_fifo_name failure/n");
exit(EXIT_FAILURE);
}
printf("res == %d/n",res);
read_res = read(res,temp_data_ptr,256);
printf("read_res = %d/n",read_res);
if(read_res > 0)
{
printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>server.c/n");
printf("get data from client /n");
printf("data was %s/n",temp_data_ptr);
while(*temp_data_ptr)
{
*temp_data_ptr = toupper(*temp_data_ptr+1);
temp_data_ptr++;
}
client_fifo_fd = open(CLIENT_FIFO_NAME,O_WRONLY);
if(client_fifo_fd == -1)
{
printf("open write client_fifo_name/n");
exit(EXIT_FAILURE);
}
write(client_fifo_fd,temp_data_ptr,BUFFER_SIZE);
}
close(client_fifo_fd);
exit(EXIT_SUCCESS);
}
客户程序如下:#include "cliser.h"
#include<fcntl.h>
int main(int argc,char *argv[])
{
int res;
char buffer[BUFFER_SIZE];
int write_res;
int read_res;
int client_fifo_fd;
memset(buffer,'/0',strlen(buffer));
memcpy(buffer,"Hello world",30);
// unlink(SERVER_FIFO_NAME);
res = open(SERVER_FIFO_NAME,O_WRONLY);
printf("res = %d/n",res);
if(res == -1)
{
printf("open %s write Failure/n",SERVER_FIFO_NAME);
exit(EXIT_FAILURE);
}
write_res = write(res,buffer,strlen(buffer));
if(write_res > 0)
{
printf("*****************************client.c/n");
printf("write some data in fifo/n");
printf("data content was %s/n",buffer);
}
mkfifo(CLIENT_FIFO_NAME,0777);
sleep(5);
client_fifo_fd = open(CLIENT_FIFO_NAME,O_RDONLY);
if(client_fifo_fd == -1)
{
printf("CLinet_fifo_name no write data/n");
exit(EXIT_FAILURE);
}
read_res = read(client_fifo_fd,buffer,strlen(buffer));
if(read_res > 0)
{
printf("from client_fifo fetch data/n");
printf("data content was %s/n",buffer);
}
close(res);
close(client_fifo_fd);
exit(EXIT_SUCCESS);
}
在运行过程中,红色标记的地方通不过,请问可以哪位大哥帮我看下,server从阻塞状态到执行过程中res = 3;但read_res = -1?不知为何解;
#include "cliser.h"
#include<fcntl.h>
int main(int argc,char *argv[])
{
int res,client_fifo_fd;
char *temp_data_ptr;
int read_res;
mkfifo(SERVER_FIFO_NAME,0777);
res = open(SERVER_FIFO_NAME,O_RDONLY);
if(res == -1)
{
printf("open read server_fifo_name failure/n");
exit(EXIT_FAILURE);
}
printf("res == %d/n",res);
read_res = read(res,temp_data_ptr,256);
printf("read_res = %d/n",read_res);
if(read_res > 0)
{
printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>server.c/n");
printf("get data from client /n");
printf("data was %s/n",temp_data_ptr);
while(*temp_data_ptr)
{
*temp_data_ptr = toupper(*temp_data_ptr+1);
temp_data_ptr++;
}
client_fifo_fd = open(CLIENT_FIFO_NAME,O_WRONLY);
if(client_fifo_fd == -1)
{
printf("open write client_fifo_name/n");
exit(EXIT_FAILURE);
}
write(client_fifo_fd,temp_data_ptr,BUFFER_SIZE);
}
close(client_fifo_fd);
exit(EXIT_SUCCESS);
}
客户程序如下:#include "cliser.h"
#include<fcntl.h>
int main(int argc,char *argv[])
{
int res;
char buffer[BUFFER_SIZE];
int write_res;
int read_res;
int client_fifo_fd;
memset(buffer,'/0',strlen(buffer));
memcpy(buffer,"Hello world",30);
// unlink(SERVER_FIFO_NAME);
res = open(SERVER_FIFO_NAME,O_WRONLY);
printf("res = %d/n",res);
if(res == -1)
{
printf("open %s write Failure/n",SERVER_FIFO_NAME);
exit(EXIT_FAILURE);
}
write_res = write(res,buffer,strlen(buffer));
if(write_res > 0)
{
printf("*****************************client.c/n");
printf("write some data in fifo/n");
printf("data content was %s/n",buffer);
}
mkfifo(CLIENT_FIFO_NAME,0777);
sleep(5);
client_fifo_fd = open(CLIENT_FIFO_NAME,O_RDONLY);
if(client_fifo_fd == -1)
{
printf("CLinet_fifo_name no write data/n");
exit(EXIT_FAILURE);
}
read_res = read(client_fifo_fd,buffer,strlen(buffer));
if(read_res > 0)
{
printf("from client_fifo fetch data/n");
printf("data content was %s/n",buffer);
}
close(res);
close(client_fifo_fd);
exit(EXIT_SUCCESS);
}
在运行过程中,红色标记的地方通不过,请问可以哪位大哥帮我看下,server从阻塞状态到执行过程中res = 3;但read_res = -1?不知为何解;
相关文章推荐
- linux 命名管道fifo实现进程间小数据通信
- 使用pipe()与fork()函数通过管道实现父子进程之间的通信
- 匿名管道实现父子进程之间的通信....
- WM_COPYDATA实现进程间数据通信
- 使用管道实现进程间的通信
- 采用虚拟命名管道的字符设备和阻塞型I/O实现进程间的通信实现KWIC程序
- 在 AIX 上通过数据管道实现进程间通讯
- Linux进程通信 有名管道实现守护进程
- 匿名管道实现父子进程之间的通信....
- 孙鑫VC学习笔记:第十七讲 用匿名管道实现进程间的通信
- 利用匿名管道技术实现本地进程通信
- 采用虚拟命名管道的字符设备和阻塞型I/O实现进程间的通信实现KWIC程序
- 实验 9-1 1. 实现以下功能 a) 调用 pipe()创建无名管道 b) 调用 fork 创建一个子进程 c) 在子进程中向管道内写入 128k 数据,打印出进程号及成功写入的字节数 d) 在父
- Python 进程线程之间通信方式(2,共享数据实现进程之间通信)
- 11.python并发入门(part10 多进程之间实现通信,以及进程之间的数据共享)
- linux进程间通过管道通信实现简单的tftp
- 采用虚拟命名管道的字符设备和阻塞型I/O实现进程间的通信实现KWIC程序
- 管道用于进程通信的实现
- APUE学习之----进程通信pipe实现管道