I'm new to Perl and I'm working on a client socket program that sends files to a server socket program. The problem I'm having is that the file never gets populated with data on the server.
The confusing part is if I change the while loop to while(<$client>) and put the $client = $server->accept(); above the loop, it works. This doesn't do me any good though because I need the server to continuously wait for new files from the client.
Thanks for the help.
#!/usr/contrib/bin/perl -w
use IO::Socket;
use Proc::Daemon;
Proc::Daemon::Init;
$receivefile = ">test.CONF";
$server = IO::Socket::INET->new(
Listen => 5,
LocalAddr => 'localhost',
LocalPort => 5050,
Proto => 'tcp',
Reuse => 1,
Type => SOCK_STREAM
) or die "Can't create server socket: $!";
open FILE, $receivefile or die "Can't open: $!";
while ($client = $server->accept()) {
print FILE $_;
}
close($client);