SPUG: IO::Socket Question

David Bitseff dbitsef at uswest.com
Thu Aug 10 20:11:35 CDT 2000

Keep in mind that when using the lower level sysread and syswrite
functions you should not use buffered reads and writes (like print and
<FILHANDLE>) on the same filehandle.  I think it says this somewhere
in the perldoc.

>> 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>

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

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

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

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

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

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     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