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
#!/usr/bin/perl -l use warnings; use strict; #use diagnostics; use IO::Socket; use IO::Select; use IO::Handle; my $stdin = IO::Handle->new(); $stdin->fdopen(fileno(STDIN),"r"); my $remote_host = "192.168.2.2"; my $remote_port = 5000; my $clientsock = IO::Socket::INET->new(PeerAddr => $remote_host, PeerPort => $remote_port, Proto => "tcp", Type => SOCK_STREAM) or die "Konnte kein Kontakt zu $remote_host:$remote_port herstellen : $@\n"; my $sel = IO::Select->new(); $sel->add($stdin); $sel->add($clientsock); my $socket; while (1) { my @readyhandles = $sel->can_read(); foreach $socket (@readyhandles) { if ($socket == $stdin) { print $clientsock <$socket>; } else { print <$socket>; } } }
print {$clientsock} <$socket>;