#!/usr/bin/perl
use strict;
use warnings;
use Socket;

my $port = 9999;

my $server;
socket($server, PF_INET, SOCK_STREAM, getprotobyname('tcp'));
bind($server, sockaddr_in($port, INADDR_ANY)) or die $!;
listen($server, 10);
while(1){
    my $client;
    my $paddr = accept($client, $server);
    my ($port, $iaddr) = sockaddr_in($paddr);
    my $name = gethostbyaddr($iaddr, AF_INET);
    print $client "Smile from the server.";
    print "Connection received from $name\n";
    close $client;
}