OK, I'm trying this IO::Socket stuff out for the firat time and I'm not having much luck. I've tried a million things. The code right out of Camel v2 doesn't even work for me. No errors, just refused conections. Is it me? any and all comments welcomed and appreciated.
the server:
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
the client:
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);
I've looked in the Camel; I've seen
MP3 server with IO::Socket (stealum much code there),
Where can I find resources about Socket, IO::Socket, IO::Socket::INET, and
forking server but nothing going from any of them...