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

how do you make a server program accept connections infinitely?

by Anonymous Monk
on Apr 04, 2000 at 18:35 UTC ( #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!
  • 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, 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
    LanX explains much cargo bla ...
    [Eily]: what? I thought PHP was known for its reliable and consistent behaviour and documentation!
    [LanX]: ... and a lot of pseudo Perl experts
    [Eily]: though honestly, I'm sure I have seen people use closure to mean anonysub for perl as well
    [stonecolddevin]: good morning friends
    [LanX]: yes, mainly pseudo Perl experts
    [Eily]: good morning stonecolddevin
    LanX has to go/
    [Eily]: bye LanX

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (10)
    As of 2018-02-23 17:15 GMT
    Find Nodes?
      Voting Booth?
      When it is dark outside I am happiest to see ...

      Results (305 votes). Check out past polls.