use DBI; use IO::Socket::INET; ### flush after every write $|= 1; ### infinite loop while(1) { my($socket, $client_socket); my($peeraddress, $peerport); my($row, $data); my @processes= ('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'); # creating object interface of IO::Socket::INET modules which internally does # socket creation, binding and listening at the specified port address. $socket = new IO::Socket::INET ( LocalHost=> '127.0.0.1', LocalPort=> '5000', Proto=> 'tcp', Listen=> 5, Reuse=> 1 ) or die "ERROR in Socket creation: $!\n"; print "I am waiting clients to connect on port 5000.\n"; while($row= shift(@processes)) { $client_socket = $socket->accept(); $peeraddress = $client_socket->peerhost(); print "Sending $row to $peeraddress:$peerport)... "; # write to the newly accepted client. print $client_socket "$row\n"; # read from the newly accepted client. $data = <$client_socket>; chomp($data); print "got $data from client.\n"; $client_socket->close(); } $socket->close(); }