jdv79 has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use IO::Socket; use IO::Select; use strict; ##INITIALIZE VARS## my $host = ($ARGV[0] || 'localhost'); my $port = ($ARGV[1] || '5501'); my $cmd1 = "act-user::dacsmaster:jdv::passwd;\n"; my $cmd2 = "rtrv-crs-t1::all:jdv;\n"; ##CREATE SOCKET## my $sock = IO::Socket::INET->new(PeerAddr => "$host", PeerPort => "$port", Proto => 'tcp', Type => SOCK_STREAM ); die "Socket could not be created. Reason: $!\n" unless $sock; $sock->autoflush(1); ##WRITE TO SOCKET## my $length = length($cmd1); syswrite($sock,$cmd1,$length); ##READ FROM SOCKET## my $read = ''; # Initialise to an empty set # (NOTE: $read=0 is very wrong) vec($read, fileno($sock), 1) = 1; # Set the appropriate bit #vec($read, fileno(FILE2), 1) = 1; # And for another file... for(;;) { my $found = select($read, undef, undef, undef); print "while loop ran\n"; # Does FILE1 have data waiting? if (vec($read,fileno($sock), 1)) { sysread($sock,my $line,1024); print "LINE:"."$line\n"; } else { print "nothing to read\n!"; last; } } print "after for loop\n"; ##CLOSE SOCKET AND EXIT## close($sock) || die "$!"; exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: socket reading...
by wog (Curate) on Jul 28, 2001 at 00:56 UTC | |
by jdv79 (Sexton) on Jul 28, 2001 at 03:56 UTC | |
by wog (Curate) on Jul 28, 2001 at 04:29 UTC | |
by tye (Sage) on Jul 28, 2001 at 11:00 UTC | |
|
Re: socket reading...
by Moonie (Friar) on Jul 28, 2001 at 01:20 UTC | |
|
Re: socket reading...
by traveler (Parson) on Jul 28, 2001 at 01:45 UTC | |
by jdv79 (Sexton) on Jul 28, 2001 at 03:50 UTC | |
by traveler (Parson) on Jul 28, 2001 at 19:37 UTC | |
|
Re: socket reading...
by bikeNomad (Priest) on Jul 28, 2001 at 21:09 UTC | |
by kschwab (Vicar) on Jul 28, 2001 at 21:28 UTC | |
|
Re: socket reading...
by petral (Curate) on Jul 29, 2001 at 19:11 UTC | |
by jdv79 (Sexton) on Jul 30, 2001 at 22:57 UTC | |
by petral (Curate) on Jul 30, 2001 at 23:17 UTC | |
by jdv79 (Sexton) on Jul 31, 2001 at 02:18 UTC | |
by petral (Curate) on Jul 31, 2001 at 20:16 UTC |