FIFO服务器程序 [英] FIFO server program

查看:244
本文介绍了FIFO服务器程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以上程序我在linux键入。它基本上具有对客户端和服务器连接在单独的终端。但是,当我在正确的顺序运行它们,即


  1. 编译服务器 - >运行服务器

  2. 编译客户端 - >运行客户

该终端只是不执行任何操作。它甚至犯规打印试图连接第一个的一部分的printf 语句。什么是这里的错误呢?

修改

我检查 mkfifo子的返回值作为@parapura拉库玛说。但仍保持相同。这是我改变code服务器。

 如果(mkfifo子(FIFO1,0666)小于0){
  的printf(错误);
}
如果(mkfifo子(FIFO2,0666)℃,){
  的printf(错误);
}
fflush(标准输出);


解决方案

您做出僵局。服务器等待打开(FIFO1,O_RDONLY)和客户端等待打开(FIFO2,O_RDONLY)。

编辑client.c:

  INT writefd =打开(FIFO1,O_WRONLY);
INT readfd =打开(FIFO2,O_RDONLY);

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

  1. Compile server -> run server
  2. Compile client - > run client

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

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);

解决方案

You made deadlock. Server wait open("fifo1",O_RDONLY) and client wait open("fifo2",O_RDONLY).

Edit client.c:

int writefd = open("fifo1",O_WRONLY);
int readfd = open("fifo2",O_RDONLY);

这篇关于FIFO服务器程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆