FIFO服务器程序 [英] FIFO server program
问题描述
>
程序我输入linux。它基本上必须在单独的终端中连接客户端和服务器。但是当我以正确的顺序运行它们,即
The above program i have typed in linux. It basically has to connect a client and server in separate terminals. But when i run them in the correct order, i.e
- 编译服务器 - >运行服务器
- 编译客户端 - >运行客户端
终端不做任何事情。它甚至不打印尝试连接
部分的第一个 printf
语句。这里的错误是什么?
The terminals just dont do anything. It doesnt even print the "Trying to connect"
part of the first printf
statement. What is the mistake here?
EDIT
mkfifo
as @parapura rajkumar说。但仍然是一样。这是我为服务器修改的代码。
I checked for return value of mkfifo
as @parapura rajkumar said. But Still it remains the same. Here is my changed code for server.
if(mkfifo("fifo1",0666)<0) {
printf("Error");
}
if(mkfifo("fifo2",0666)<0) {
printf("Error");
}
fflush(stdout);
推荐答案
服务器等待打开(fifo1,O_RDONLY)和客户端等待打开(fifo2,O_RDONLY)。
You made deadlock. Server wait open("fifo1",O_RDONLY) and client wait open("fifo2",O_RDONLY).
编辑client.c:
Edit client.c:
int writefd = open("fifo1",O_WRONLY);
int readfd = open("fifo2",O_RDONLY);
这篇关于FIFO服务器程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!