I'm running a socket server program that receives files from a perl client. When the files are received, they are printed out to a directory. The programs function fine, the question I have, is does anyone have suggestions on how to speed up the receipt of the files? It's not as fast as I'd like it to be. Below find the main portion of the socket server code.
Thanks - Keith
$server = IO::Socket::INET->new(
Listen => 5,
LocalPort => 1111,
Proto => 'tcp',
Reuse => 1,
Type => SOCK_STREAM
) or die "Can't create server socket: $!";
while ($client = $server->accept()) {
$receivefile = $receivepath . $timestamp . ".ord";
$client->autoflush(1);
open FILE, $receivefile or die "Can't open: $!";
while (<$client>) {
if (substr($_,0,4) ne $trnh && substr($_,0,4) ne $ordh && substr($
+_,0,4) ne $ordl && substr($_,0,4) ne $endt && substr($_,0,4) ne $trlr
+) {
$sizereceived = substr($_,0,5);
print FILE substr($_,5);
}
else {
print FILE $_;
}
$client->autoflush(1);
sleep(1);
} #End While Receiving from Client
close FILE;
check_size();
#If the filesize sent doesn't match
#the filesize received, send an error
#email. !!!Do not indent this if statement,
#the sendmail won't work!!!
if ($filesize != $sizereceived) {
move_badfiles();
$badpath = substr($receivefile,41);
#Start SENDMAIL
open(SENDMAIL, "|/usr/lib/sendmail -oi -t -odq");
print SENDMAIL <<"EOF";
From: marc
To: someone\@someplace.com
Subject: Distn Planning File Error!
File $badpath has not be transmitted properly. Check the badinput dir
+ectory.
EOF
close(SENDMAIL);
}
else {
move_files();
}#End else
$timestamp = strftime("%m%d%Y%H%M%S", localtime());
$receivetime = strftime("%m/%d/%Y %H:%M:%S", localtime());
print "Successfully received $receivefile at $receivetime\n";
close($client);
}#End receiving connection