Perl Client

The following Perl code is an example for an ONLINE client. It can be started after an ONLINE session prepared for a connect with, e.g. server/asynch.

#!/usr/bin/perl
#
# this script reads (Spectra/online) commands from STDIN and 
# sends them to a remote server (hasexp). The server has been 
# started with:
#
# ONLINE> server/asynchr 7777
#
# Usage: 
#
#  # tcp_client [host [port]]
#
#    Defaults: 
#      host - hasexp
#      port - 7777
#
use Net::Gen; 
use Net::Inet; 
use Net::TCP; 

$host = shift @ARGV || "hasexp"; 
$port = shift @ARGV || 7777; 

print "\n";
tie $x,Net::TCP, $host, $port or die "Failed to tie \$x \n";
while(1)
{
    print "Enter> ";
    $com = <STDIN>;               # read a command from STDIN
    $com =~ s/^\s*(.*?)\s*$/$1/;  # remove leading/trailing white space

    last if( $com =~ /^(x|X)$/ ); # 'x' terminates the loop

    next if ! $com;               # $com empty? re-read

    $x = "$com\n";                # send the command 
    $ans = $x;                      # receive the answer

    $ans =~ s/^\s*(.*?)\s*$/$1/;  # remove leading/trailing white space
    print "Answer: $ans \n";      # display the answer 

    $com =~ tr/A-Z/a-z/;          # answer lo lower case letters
    last if( $com =~ /^bye$/);    # sending 'bye' terminates the server
}
untie $x;