SPUG: IO::Socket Question

ced at carios2.ca.boeing.com ced at carios2.ca.boeing.com
Thu Aug 10 14:24:29 CDT 2000

> I think you (and everyone else) are on the right track. However, it still
> doesn't work :)

> If I open up the socket to a web server and request a page (so I'm
> getting a decent amount of data back) it works fine.

> however, with the server I'm connecting to, where all it replies with is
> one work, it hangs on the line referencing <$sock>

If you're just getting a one-word response with no newline,
then, <$sock> will still hang because it's line oriented
and will wait for a newline.

Here's a section from IO::Select that provides another
possible strategy:

     If the remote server sends data a byte at time, and you need
     that data immediately without waiting for a newline (which
     might not happen), you may wish to replace the while loop in
     the parent with the following:

         my $byte;
         while (sysread($handle, $byte, 1) == 1) {
             print STDOUT $byte;

     Making a system call for each byte you want to read is not
     very efficient (to put it mildly) but is the simplest to
     explain and works reasonably well.

Charles DeRykus

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For full traffic, use spug-list for LIST ; otherwise use spug-list-digest
  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/

More information about the spug-list mailing list