#!/usr/bin/perl use warnings; use strict; use IO::Socket::INET; # Main socket, it's only for accepting connections my $sock = IO::Socket::INET->new(LocalPort => 10000, Proto => 'tcp', Listen => 2) or die "unable to initiate socket: $!"; print STDERR "ready to accept connections\n"; # Working sockets, they're bidirectional connections towards each # single client, so they're to be used for actual communications my $conn1 = $sock->accept() or die "accept(): $!"; print STDERR "client 1 connected\n"; my $conn3 = $sock->accept() or die "accept(): $!"; print STDERR "other client connected\n"; # Core of algorithm should go here, just some examples of IO given # Read from client #1 my $rec1 = <$conn1>; # Send something to client #1 print $conn1 "Hey #1, I heard you saying [$rec1]\n"; # Read from the other client my $rec3 = <$conn3>; # Send something to it as well print $conn3 "You're there, #3... did you say [$rec3]?\n"; $_->close foreach ($conn3, $conn1, $sock);