Contributed by Anonymous Monk
on Apr 04, 2000 at 18:35 UTC
Q&A
> network programming
Description: 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 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
|
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
Outside of code tags, you may need to use entities for some characters:
| |
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.
|
|