in reply to Socket gripes

The problem is that with this line:
my @answer = <$socket>;
you are saying to Perl to read in the whole "file", so of course it won't return until the socket is closed. Your protocol needs to have some way to tell when your server has finished talking. There are lots of ways to do this, you just have to make sure that your data won't accidentally trigger that condition.

Common ways are to:

  1. prefix the response with the length of the data
  2. or, send a blank line when you're done
  3. or, send a dot on a line by itself
  4. or, prefix each line with some character that indicates whether or not it's the last line

Replies are listed 'Best First'.
Re: Re: Socket gripes
by John M. Dlugosz (Monsignor) on Oct 25, 2002 at 18:44 UTC
    Why would that read the whole file for $socket, when he's not changing the global $/ (input record separator)?
      Because he is using < > (readline) in list context.
Re: Re: Socket gripes
by frankus (Priest) on Oct 25, 2002 at 15:50 UTC
    I'm sure it's not the friday afternoon beers speaking ( that the managers dispense like Captain Ahab..
    "Drink and pass!" he cried, handing the heavy charged flagon to the
    nearest seaman.  "The crew alone now drink.  Round with it, round!
    Short draughts--long swallows, men; 'tis hot as Satan's hoof."  
    
    )

    I digress... I am sure it is not the ale speaking when I say many thanks for this precise and calming answer ;o)

    --

    Brother Frankus.