Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

how do you make a server program accept connections infinitely?

by Anonymous Monk
on Apr 04, 2000 at 18:35 UTC ( [id://6841]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

If you could give me an example I would be thankful to you Vishu

Originally posted as a Categorized Question.

  • Comment on how do you make a server program accept connections infinitely?

Replies are listed 'Best First'.
Re: how do you make a server program accept connections infinitely?
by btrott (Parson) on Apr 04, 2000 at 20:53 UTC
    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"?
Re: how do you make a server program accept connections infinitely?
by mslattery (Initiate) on Apr 19, 2002 at 18:28 UTC
    Vishu,

    This is just further information about how sockets can work for you!

    btrott gave you a good example of a single threaded, io blocked socket example.

    But there are many variations. What exactly are you looking to do?

    Single or multiple connections?
    Blocking or Nonblocking IO
    Let me know and I'll see how I can help you.

    Thanks,
    mslattery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://6841]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-19 16:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found