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 IO::Socket; $| = 1; my $c_con = new IO::Socket::INET( LocalHost => '127.0.0.1', LocalPort => '81', Proto => 'tcp', Listen => 1, Reuse => 1 ); die "Could not create socket: $!\n" unless $c_con; my $s_con = new IO::Socket::INET( PeerAddr => 'beispiel.tld', PeerPort => '80', Proto => 'tcp', ); die "Could not create socket: $!\n" unless $s_con; my $client_data = $c_con->accept(); $client_input = <$client_data>; # GET / HTTP/1.1\n $client_input.= <$client_data>; # host: beispiel.tld\n print $s_con "$client_input\n"; # an den tatsächlichen HTTP-Server schicken $result = ""; while ($server_output = <$s_con>) { $result .= $server_output; # Antwort bekommen... } # ??? und hier fängt der Ärger an: ??? $c_con->send($result."\n\n"); #weder das hier noch die folgenden 5 Zeilen sorgen für eine Antwort an den Client(Browser) print $c_con "$result\n\n"; while (my $c_answer = $c_con->accept()) { print $c_answer "$result\n\n"; $c_answer->send($result."\n\n"); } close($c_answer); close($s_con); close($c_con); exit;