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);
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.