#!/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; } }