in reply to How can I determine the server is waiting for input in POE::Wheel::ReadWrite?

If your client/server protocol is line-based, then presumably your server would send some kind of "end of job" marker. Your client can detect this marker and begin the next job.

For example, SMTP uses a single period on a line by itself to signal the end of a message body. Be careful to prevent jobs from including that text in their output. SMTP escapes body lines that are single periods so that they aren't confused with end-of-message markers.

  • Comment on Re: How can I determine the server is waiting for input in POE::Wheel::ReadWrite?

Replies are listed 'Best First'.
Re^2: How can I determine the server is waiting for input in POE::Wheel::ReadWrite?
by woosley (Beadle) on Nov 15, 2009 at 08:51 UTC
    Thanks for the reply, this is a solution.
    But I do prefer POE can auto-detect that the server side has send out it's output. I can "telnet" to the server and run these commands, when the command sent out the result, I can input another command. Is any possible way to do it without adding any end mark?

      Hi,

      When you send messages across a network, they get chopped up into pieces. The problem is: you cannot know ahead of time how many pieces the message will get chopped up into. Therefore, the only way to know when to stop trying to read the bits and pieces of the messages coming across the network is if there is some kind of "end of message" marker.

      Some other "end of message" markers are: If the other side of the connection is always guaranteed to send messages of the same length, you can stop reading after receiving x number of bytes. Or, if the other side always uses the first two bytes of the message to indicate how many bytes the message length is, you can read the first two bytes, then read the next x number of bytes after that and then stop reading. Or, if the other side always closes the connection after sending a message, you can use that event as an end of message marker.

      But the bottom line is you can't automatically detect when to stop reading because you can't know ahead of time how many pieces your message got chopped up into when it was sent across the network.

      I hope that helps shed some light on the situation.

        Thanks, you really did a lot of help. I think I have some confusion in the basic idea of net work programming which this reply clarified. So the choice is to set a end mark for each command.
        thanks all

      I can "telnet" to the server and run these commands, when the command sent out the result, I can input another command.

      How do you know the command finished sending out the result? By the prompt you are given once it's done. Or maybe because you recognize the format of the output. Or maybe you assumed it was done based on the passing of time. Those are examples of the aforementioned "end of job marker".

      A computer cannot detect the appropriate condition without being told what it is. There's too much variety in the possibilities. They usually come in two varieties:

      • A prefix that indicates how much data is coming.

        For example,

        • Perl strings are stored as a structure that include length field.
        • The header of IP packets indicate how big the packet is.
        • HTTP response can indicate the size of the response in the Content-Length header.
      • A sentinel value indicates the end has been received.

        For example,

        • C strings end at the first occurrence of byte '\0'.
        • bash indicates it's ready for another command by echoing $.
        • HTTP response without a Content-Length header are ended by socket closure.

      If you're doing it by hand how do you determine that the command has finished its output?