Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use strict; use threads; use threads::shared; use IO::Socket::INET; $| ++; my $listener = IO::Socket::INET->new ( LocalPort => 1337, Listen => 5, Reuse => 1 ) || die "Cannot create socket\n"; warn "server up and ready for connections...... \n"; my $client : shared; my $client_num = 0; my @grab; while (1) { our $client = $listener->accept; threads->create(\&start_thread, $client, ++ $client_num); } sub start_thread { my ($client, $client_num) = @_; print "thread created for client $client_num\n"; push @grab, $client; print @grab; print $client "Welcome to the Test server!\n"; &begin; } sub begin { while(our $line = <$client>) { print $client $line; print $line; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: sharing variables with threads
by pg (Canon) on Mar 13, 2003 at 03:12 UTC | |
by jasonk (Parson) on Mar 13, 2003 at 03:20 UTC | |
by pg (Canon) on Mar 13, 2003 at 03:43 UTC | |
|
Re: sharing variables with threads
by Anonymous Monk on Mar 13, 2003 at 05:16 UTC | |
|
Re: sharing variables with threads
by jasonk (Parson) on Mar 13, 2003 at 01:49 UTC | |
by Anonymous Monk on Mar 13, 2003 at 01:53 UTC | |
by jasonk (Parson) on Mar 13, 2003 at 02:05 UTC | |
by Anonymous Monk on Mar 13, 2003 at 02:09 UTC |