Iulian Muntean
Iulian Muntean

Reputation: 3

client-server application using fifos

I'm trying to write a client-server application in C using 2 fifos (client_to_server and server_to_client). A version of the app where the client writes a command to the server who reads it works well, but when I add in client the lines in order to read the answer from the server it doesn't work anymore: the server gets blocked in reading the command from the client (as if there is nothing in client_to_server fifo, although the client written in it). What could be the problem in this case?

Upvotes: 0

Views: 114

Answers (1)

Serge Ballesta
Serge Ballesta

Reputation: 149155

You are using fputs to send data to the server. That means that the data could stay in a local buffer until the buffer is full or you explicitely flush it. When you do not wait for the answer but exit from the client, the fifo is implicitely flushed and closed, causing the server to recieve something. But if you start waiting in the client without a prior flush, you end with a deadlock.

But remember: pipes were invented for single way communications. If you want 2 way communications with acknowlegements and/or synchronizations, you should considere using sockets.

Upvotes: 1

Related Questions