hi.
okay. versuchs mal so
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use strict;
use IO::Socket;
use IO::Socket::INET;
my $CRLF = chr(13).chr(10);
use constant SERVER_PORT => 40411;
use constant KEEPALIVESEC => 10;
my $sock = IO::Socket::INET->new(PeerHost => 'localhost', PeerPort => SERVER_PORT, Proto => 'tcp');
if($sock->connected)
{
print "KARAMBA\n";
local $SIG{ALRM} = sub {
if($sock->connected)
{
$sock->write("E$CRLF", 3);
$sock->getline();
alarm KEEPALIVESEC;
}
}
alarm KEEPALIVESEC;
my $request = "";
my $response = "";
while(lc($request) ne "quit" and lc($response) ne "quit")
{
print "Eingabe: \n";
$request = <STDIN>;
alarm KEEPALIVESEC; # alarm reset (hoffentlich; kenn ich damit gar nicht aus)
chomp $request;
$sock->write("$request$CRLF", length($request)+2);
print "YOU wrote: [$request]\n";
$response = $sock->getline();
chomp $response;
$response =~ s!$CRLF$!!g; # to be sure
print "SERVER wrote: [$response]\n";
}
alarm 0; # race condition protection
}
spaß\n\n
<!--EDIT|esskar|1090329368-->