#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, Listen=>$max_clients, Reuse=>1); # create a new selection and add our basic socket for incoming connections $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 prints 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++; } }