#!/usr/bin/perl use strict; use warnings; use IO::Socket; use File::Basename; use Communication; do_the_re(15, 'a b c d', '\s*(b)\s*(c)\s*'); do_the_re( 5, 'a b c d', '\s*(b)\s*(c)\s*'); do_the_re( 5, 'a b c d', '\s*(e)\s*'); do_the_re( 2, 'a b c d', '(?{sleep 3})'); sub do_the_re { my ($timeout, $txt, $re) = @_; my $remote_host = 'localhost'; my $remote_port = 4714; my $socket = IO::Socket::INET->new( PeerAddr => $remote_host, PeerPort => $remote_port, Proto => 'tcp', Type => SOCK_STREAM, ) or die "Konnte Verbindung zu $remote_host:$remote_port nicht herstellen: $@\n"; print "Client ", basename($0), " is starting, connected to $remote_host:$remote_port ...\n"; print $socket Communication::RE_REQUEST, "\n"; chomp(my $antwort = <$socket>); die "no server-accept\n" unless $antwort eq Communication::ACCEPT; print $socket "$timeout\n$txt\n$re\n"; chomp(my @erg = <$socket>); if (@erg == 1 and $erg[0] eq Communication::TIME_OUT) { print "ABBRUCH WEGEN ZEITUEBERSCHREITUNG\n"; } elsif (@erg == 1 and $erg[0] eq Communication::NO_MATCH) { print "KEIN MATCH\n"; } else { print "Ergbenis: [", join('], [', @erg), "]\n"; } }