#  SocketClient.pl
#  Example: 7.23
#  ----------------------------------------
#  From "Win32 Perl Scripting: Administrators Handbook" by Dave Roth
#  Published by New Riders Publishing.
#  ISBN # 1-57870-215-1
#
#  This script is the client that connects to the daemon code in 
#  Example_11_22.pl and Example_11_24.pl

use IO::Socket;

$Host = "localhost" unless( $Host = $ARGV[0] );
$Port = 8080;

print "Connecting to $Host:$Port...\n";
if( $Socket = IO::Socket::INET->new( "$Host:$Port" ) )
{
    while( $In = $Socket->getline() )
    {
        print "Socket client: $In";

        my $Data = <STDIN>;
        $Socket->print( $Data );
    }
    $Socket->close();
}
else
{
    print "Failed to connect.\n";
}
