Hello wise monks. I need to write code that will stay connected to another server continuously 24x7. Will the following code do the job? Or should I use infinite loops? If so, how?
use IO::Socket;
use strict;
my $socket;
my $line;
my $child_pid;
$socket = IO::Socket::INET->new
(
PeerAddr => 'server.com',
PeerPort => 1247,
Proto => "tcp",
Type => SOCK_STREAM
) or die "Could not create client.\n";
unless (defined($child_pid = fork())) {die "Cannot fork.\n"};
if ($child_pid)
{
while($line = <>)
{
#here I'm gonna make the server read some files and
#throw stuff to the other socket
}
}
else
{
while ($line = <$socket>)
{
#here I'm gonna make the server listen for stuff from
#the other socket. The information that comes from this
#connection will be store in files that will be accessed
#by the parent process. Is this gonna work? 24x7?
#Non-stop?
}
}
Thanks