Here's some semi-tested client code that reads what it can. then does the inner loop for each whole line.

# cli.pl: use strict; use warnings; use IO::Select; use IO::Socket; my $sock = IO::Socket::INET->new('127.0.0.1:1235') or die "sock: $@"; my $sel = IO::Select->new($sock); my $buffer = ''; while(@1 = $sel->can_read(2) and sysread $sock, $buffer, 4096, length +$buffer) { while( $buffer =~ s/^.*\n// ) { my $line = $&; print "got: ", $line; # or whatever processing you want here... } } die @1 ? "socket closed" : "timeout";

If you change the read size to 1 you get the read-a-byte-at-a-time behavior.


In reply to Re^7: IO::Socket tutorial by tybalt89
in thread IO::Socket tutorial by BernieC

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":