http://www.perlmonks.org?node_id=197484

masuoda has asked for the wisdom of the Perl Monks concerning the following question:

which solution you suggest to me for writting a powerful socket server ?! Use traditional IO::Select or Thread in 5.8? Please tell me your reasons if you have suggesstion.
#!/usr/bin/perl -w #Traditional IO::Select Example use IO::Select; use IO::Socket; $Server = new IO::Socket::INET(Listen => 0, LocalPort => 4000, Reuse = +> 0) || die('Can not open port 4000'); $Select = new IO::Select( $Server ); while(@allSockets = $Select->can_read) { foreach $ClientSocket (@allSockets) { if($ClientSocket == $Server) { $newClient = $Server->accept; $Select->add($newClient); } else { .... } }
#!/usr/bin/perl -w #New stable Thread module in 5.8 use IO::Socket; use Thread; $Server = new IO::Socket::INET(Listen => 0, LocalPort => 4000, Reuse = +> 0) || die('Can not open port 4000'); while(1) { $newClientSocket=$Server->accept; new Thread \&handleRequest,$newClientSocket; } sub handleRequest() { $clientSocket=shift; ... }