Hello!

I implement the server through named pipes, I encountered a problem ... Here is the task: The client reads text from stdin and sends it to the server, the server returns it to the client. The client prints to server stdout the response of the server and the time elapsed between sending text to the server and receiving a response from the server.

Tell me, how can I inform the client about the end of recording in the channel? (I have a server-one program with two processes: the 1st writes to the channel, the 2nd reads from it, and the client is different.)

  • If a simple string is passed, maybe '\0' will mark the end of the transfer? - skegg
  • one
    Closing the file by the writing process causes read to exit the wait. - sercxjo
  • one
    @Alerr, synchronization through signals ... I don’t really like it, but for labs you can probably. And how exactly did you cut off ubuntu? So what should be done in a lab so that the axis breaks? - avp
  • one
    @alexlz, and select () does not change anything in this situation. Here the client will write in the fifo data, call select (), he will inform him that there is data in the fifo, the client will read them (just written to them) and. - avp
  • one
    @avp After talking with local sorcerers can move the roof. @Alerr What does "ending the recording in the channel" mean? There will no longer be written there, or is just another portion recorded, should it be taken away? - alexlz 5:58

1 answer 1

@Alerr , well, the idea (absolutely unproductive) here can be very simple. The client at the beginning of his message writes the server his pid, and the server before the echo his.

 cli -> c-pid text cli pause cli <- s-pid text cli kill s-pid serv <- c-pid text serv -> s-pid text serv kill c-pid serv pause 

For a couple this should work.

Are you sure that you need this mutoten? Can a task be interpreted a little differently?

  • figured out, everything is simpler, no need to send a signal to the server so that it reads special chips there: 1 you need to use something that is not read from an empty channel, 2 writes / reads only one process from a channel ... - Alerr
  • @Alerr, you are confusing something. Do you have a server that writes an echo in the same channel that is reading? - avp
  • one
    @sercxjo, my comments ran out. You write If you read and write through one descriptor, then the data written to it should not be returned through it unfortunately this is not so. Make write () in FIFO and right there (with the same descriptor (and maybe with another - no difference)) read () and read the bytes just written. If you read several processes, you can read another, then you will wait on this read () until someone writes to this FIFO (or exit the signal through a signal). - avp
  • checked, yes read back and through the same descriptor, if the server is confused, the client will read himself - sercxjo
  • @sercxjo, my comments ran out. The author has already said about 2, fifo, this is not my whim, this is a lecturer wrote to the lab ..... No, you can't do the 2nd channel ... ugly, I agree, but you can do echo. - avp