Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

how do you make a server program accept connections infinitely?

( #6841=categorized question: print w/ replies, xml ) Need Help??
Contributed by Anonymous Monk on Apr 04, 2000 at 18:35 UTC
Q&A  > network programming


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

Answer: how do you make a server program accept connections infinitely?
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"?
Answer: how do you make a server program accept connections infinitely?
contributed by mslattery


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.


Please (register and) log in if you wish to add an answer

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • 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, 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, 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (7)
    As of 2015-10-10 13:51 GMT
    Find Nodes?
      Voting Booth?

      Does Humor Belong in Programming?

      Results (257 votes), past polls