#!/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;