O'Reilly logo

Programmieren mit Perl by Jon Orwant, Tom Christiansen, Larry Wall

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

IO::Socket

use IO::Socket;

Als Client:

$socket = new IO::Socket::INET (PeerAddr => $remote_host,
                                PeerPort => $remote_port,
                                Proto   => "tcp",
                                Type    => SOCK_STREAM)
 or die "Kann Verbindung zu $remote_host:$remote_port nicht herstellen: $!\n";

# Hier die einfachere Ein-Argument-Schnittstelle.
$socket = IO::Socket::INET->new("$remote_host:$remote_port");
                                 # Zum Beispiel "localhost:80".
print $socket "data\n";
$line = <$socket>;

Als Server:

$server = IO::Socket::INET->new(LocalPort => $server_port, Type => SOCK_STREAM, Reuse => 1, Listen => 10 ) # or SOMAXCONN or die "Kann kein TCP-Server an Port $server_port sein: $!\n"; while ($client = $server->accept()) { # $client enthält die neue Verbindung $request = <$client>; print $client "answer\n"; close $client; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required