Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Answer: how do you make a server program accept connections infinitely?

by btrott (Parson)
on Apr 04, 2000 at 20:53 UTC ( #6855=categorized answer: print w/replies, xml ) Need Help??

Q&A > network programming > how do you make a server program accept connections infinitely? - Answer contributed by btrott

Just open up a new socket for your server and listen on that socket for incoming connections in an accept loop. There are examples in perlipc of both the IO::Socket and, well, non-IO::Socket variety. Just in case you don't want to use that module.

Here's the basic idea:

use IO::Socket; my $port = 9000; # set up a new server running on $port my $server = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $port, Reuse => 1) or die "Can't start server"; # sit in a loop and wait for connections while ($client = $server->accept()) { # handle client # .... # done with client, so close up connection close $client; }
Is this what you meant by "infinite"?

  • Comment on Answer: how do you make a server program accept connections infinitely?
  • Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2016-09-25 02:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:







    Results (463 votes). Check out past polls.