thran has asked for the wisdom of the Perl Monks concerning the following question:
#taken from perlnet #!/usr/bin/perl use IO::Socket; # include the select package use IO::Select; # they're counting the number of connections $nconnections_old = 0; $nconnections_new = 0; $port = 1234; $new_client = IO::Socket::INET->new(Proto=>"tcp", LocalPort=>$port, Li +sten=>$max_clients, Reuse=>1); # create a new selection and add our basic socket for incoming connect +ions $sel = IO::Select->new($new_client); while (@ready = $sel->can_read) { # for every readable socket foreach $client (@ready) { # check if it is the basic socket if ($client == $new_client) { # if it is establish new connection $add = $client->accept; # add new socket to the selection $sel->add($add); # increase number of connections $nconnections_new++; # if it is an already established connectection } else { #It waits for user input here, like an enter, or somehing before it pr +ints the string in $hey to the client.. Why?? $hey="Hey, Iam the server, how are you?"; syswrite($client, $hey, length($hey)); } } # if number of connections has changed, print it if ($nconnections_old != $nconnections_new) { print "Already $nconnections_new connection(s)\n"; $nconnections_old++; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Server waits for user input before sending text.
by pjf (Curate) on Oct 07, 2001 at 01:52 UTC | |
|
Re: Server waits for user input before sending text.
by jlongino (Parson) on Oct 06, 2001 at 22:24 UTC | |
|
Re: Server waits for user input before sending text.
by thinker (Parson) on Oct 06, 2001 at 20:56 UTC | |
by thran (Novice) on Oct 06, 2001 at 21:08 UTC | |
|
Re: Server waits for user input before sending text.
by em (Scribe) on Oct 07, 2001 at 14:30 UTC | |
|
Re: Server waits for user input before sending text.
by em (Scribe) on Oct 07, 2001 at 14:33 UTC |