I have normal server code here, and i have no idea how to make it work with many clients. The server would print what one client says to every client.
Code:
#!/usr/bin/perl -w
use IO::Socket::INET;
use strict;
my $port = '1584';
my $socket = IO::Socket::INET->new('LocalPort' => $port,
'Proto' => 'tcp',
'Listen' => SOMAXCONN)
or die "Can't create socket ($!)\n";
print "[Server created at port:$port]\n";
while (my $client = $socket->accept) {
$client->autoflush(1);
my $name = gethostbyaddr($client->peeraddr, AF_INET);
printf "[Connect from %s]\n", $client->peerhost;
my $port = $client->peerport;
while (<$client>) {
print "[$name $port] $_";
print $client "[$name $port] $_";
}
close $client
or die "Can't close ($!)\n";
}
die "Can't accept socket ($!)\n";
Comment