##
$ ./tester -local
Starting up the test util with network enabled...
TestUtil>ddl drp table testa
I have received your message[server]-THISISTHEEND
DATA in $data slice 1 is THISISTHEEND
I have received your message[server]-THISISTHEEND
DATA in $data slice 1 is THISISTHEEND
TestUtil>ddl create table testa
<-it hangs and I have to ctrl+C out
####
#!/usr/bin/perl
use warnings;
use strict;
use IO::Socket qw(:DEFAULT :crlf);
my $port = $ENV{CM_PORT} || 3013 ;
my $host = $ENV{CM_HOSTS} || 'uksupu02' ;
my $read ;
my $quit ;
my $utilprmpt = 'Testing> ';
my $socket ;
my $user_input = 'start' ;
RERUN_PROMPT: while ( $user_input ne 'quit') {
print "$utilprmpt";
chomp ( $user_input = <>);
if (!$user_input){next RERUN_PROMPT } ;
if ($user_input =~/^\s+$/){ next RERUN_PROMPT } ;
if ( $user_input eq 'quit') { exit };
&CreateClient ;
}
sub CreateClient {
$socket = IO::Socket::INET->new("$host:$port") or die "can't create socket: $!";
user_to_host ($socket, $user_input) ;
&host_to_user ($socket);
}
sub user_to_host {
my $sock = shift;
my $msg = shift ;
print $sock $msg ,CRLF;
}
sub host_to_user {
my $sock = shift ; my $nread ; my $inp ;
$/ = CRLF ;
while (<$sock>) { chomp;
my @data = split/-/, $_ ;
print $_ , "\n";
if ($data[1] eq 'THISISTHEEND') {
return ;
}
}
}
####
#!/usr/bin/perl
use warnings;
use strict;
use IO::Socket qw(:DEFAULT :crlf) ;
my $port = $ENV{CM_PORT} || 3013 ;
my $quit = 0 ;
my $session ;
my $sock ;
$SIG{INT} = sub { $quit++ } ;
sub server {
$sock = IO::Socket::INET->new( Listen => 5, LocalPort => $port, Timeout => 60*60, Reuse => 1 ) or die "Can't create listening socket: $!\n";
warn "Waiting for incoming connections on port $port...\n";
}
&server ;
while ( !$quit ) {
next unless $session = $sock->accept;
my $pport = $session->peerport;
my $paddr = $session->peeraddr;
my $pname = gethostbyaddr($paddr, AF_INET);
my $peer = "$pname:$pport" ;
warn "Connection from [$peer]\n";
while (<$session>){
chomp;
my $msg_recv = $_ ;
my $msg_out = ("I have received your message[server]-THISISTHEEND") . CRLF ;
print $session $msg_out ;
print " Received=> $msg_recv \n";
}
warn "Connection from [$peer] finished\n";
close $session ;
}