Hello all. I am seeking knowledge with respect to setting up an IO::Socket Server that will have longevity. I mainly want to understand why the version I am posting below does not allow more than ~6,000 connects from a client over and over again. I have the client close the socket between reconnects. I really want to understand anything I am doing wrong so I can setup a server that will stay up and running for quite some time. I want it to survive many connections (possibly into the millions, but not at the same time).
I am running this on a Windows XP system using ActiveState Perl. I will eventually run this on a Linux box.
Any help would be greatly appreciated. Thank you in advance for your help.
=================================
use strict;
use warnings;
use IO::Socket;
my $port = 22000;
print STDOUT "Starting Server on Port $port\n";
StartServer();
sub StartServer{
my $socket = IO::Socket::INET->new(
LocalAddr => 'localhost',
LocalPort => $port,
Proto => 'tcp',
Listen => 5,
Reuse => 1,
Type => SOCK_STREAM,
) or die "Can NOT open socket for server\n\tReason: $@\n\n";
for(;;){
$socket->autoflush(1);
my $client = $socket->accept();
while (my $Request = <$client>){
print STDOUT "Request: $Request\n";
print $client "Your request $Request\n";
}
}
}
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.