[LA.pm] Hi all - a question on socket client

Benjamin J. Tilly ben_tilly at operamail.com
Mon May 3 12:29:28 CDT 2004


Kevin Scaldeferri <kevin at scaldeferri.com> wrote:
> Ranga Nathan wrote:
> > Got a question. I am testing a server that is running on the Big Iron. 
> > This trivial server simply echoes input and disconnects upon receiving 
> > 'END' or 'end'.
[...]
> > print $sock "USQ1";
> 
> 
> Since your socket connection is line-buffered, this hasn't actually been 
> sent to the server at the point when you start listening on the next line.

The classic article on problems of this nature is
http://perl.plover.com/FAQs/Buffering.html.  If the output expected
does not include a line ending, you can set autoflush on the socket.
If you're using the IO::Handle stuff you can do that with the
autoflush command, else

  my $oldfh = select(YOUR_SOCKET);
  $| = 1;
  select($oldfh);

You can also run into buffering problems on the other end of the
socket.  Read the article above for a fuller explanation.

Cheers,
Ben



More information about the Losangeles-pm mailing list