#!/usr/bin/perl -w use strict; use IO::Socket; my $port = 5566; # Posloucháme na portu my $listen = IO::Socket::INET->new('LocalPort' => $port, 'Listen' => 20, 'Proto' => 'tcp', 'Reuse' => 1) or die "Error creating listening socket: $@\n"; print "Waiting for requests or port $port.\n"; # Zpracujeme příchozí spojení while (my $connect = $listen->accept) { my $othersockaddr = $connect->peername; my ($port, $iaddr) = unpack_sockaddr_in($othersockaddr); my $otherhostname = gethostbyaddr($iaddr, AF_INET); my $otherstraddr = inet_ntoa($iaddr); print "Got connection from $otherhostname $otherstraddr\n"; # Komunikace s klientem while (<$connect>) { print $connect 'Got: ', $_; last if (/bye/i); if (/date/i) { my $time = localtime; print $connect "My date/time is $time.\n"; } } $connect->close; }