use strict;
use warnings;
use IO::Socket::INET;
my $socket = IO::Socket::INET->new(
LoclaPort => 1776,
Type => SOCK_STREAM,
Reuse => 1,
Listen => 10 )
or die "Big Problem with the Server, Man : $!\n\n";
while ( my $client = $socket->accept() ) {
{
my $child;
# perform the fork or exit
die "Can't fork: $!" unless defined ($child = fork());
if ($child == 0)
{ #i'm the child!
#close the child's listen socket, we dont need it.
$socket->close;
#call the main child rountine
print $client 'Hello, down there!!', "\n\n";
#if the child returns, then just exit;
exit 0;
}
else
{ #i'm the parent!
#who connected?
warn "Connecton recieved ... ",$client->peerhost,"\n";
#close the connection, the parent has already passed
# it off to a child.
$client->close();
}
#go back and listen for the next connection!
}
}
close($socket);
####
"A man's maturity -- consists in having found again the
seriousness one had as a child, at play." --Nietzsche
####
use strict;
use warnings;
use IO::Socket::INET;
my $socket = IO::Socket::INET->new(
PeerAddr => 'localhost',
PeerPort => '1776',
Proto => "tcp",
Type => SOCK_STREAM)
or die "Big Problem, Man : $!\n\n";
my $response = <$socket>;
print $response, "\n\n" if $response;
close($socket);