#!/usr/bin/perl use warnings; use strict; use IO::Socket; use threads; $|++; print $$; my $server = new IO::Socket::INET( Timeout => 7200, Proto => "tcp", LocalPort => 12345, Reuse => 1, Listen => 2 ); my $num_of_client = -1; while (1) { my $client; do { $client = $server->accept; } until ( defined($client) ); my $peerhost = $client->peerhost(); print "accepted a client $client, $peerhost, id = ", ++$num_of_client, "\n"; #spawn a thread here for each client my $thr = threads->new( \&processit,$client,$peerhost )->detach(); } sub processit { my ($lclient,$lpeer) = @_; #local client if($lclient->connected){ # Here you can do your stuff # I use have the server talk to the client # via print $client and while(<$lclient>) print $lclient "$lpeer->Welcome to server\n"; #and #$lclient->recv; while(<$lclient>){print $lclient "$lpeer->$_\n"} } #close filehandle before detached thread dies out close( $lclient); } __END__