Tfe

Ongi etorri tfe-ren webgunera...

Old stuff/ecole_etude_fac_de_pau/perl/threads.pl

(Deskargatu)
#!/usr/bin/perl -w

use threads;
use IO::Socket::INET;






$sock = IO::Socket::INET->new(PeerAddr => 'www.perl.org',
                              PeerPort => 'http(80)',
			      Proto    => 'tcp');
print "Socket ouvert\n";
my $thread1 = threads->create(\&fonction,"arguments");

			      

#on ouvre ... tu fais ce que tu veux 
$thread1->detach;


sub fonction()
{
sleep(1);
while ($sock) { print "FERMETURE de $sock\n "; 
	    sleep(1);
           close ($sock) or print $!."\n"; 
	   }
}



sleep (10);
if ($sock) { 
    print "Socket ouvert: $sock\n"; 
    print $sock "Get \n\n\n"; 
    while($line = <$sock>) { print "$line\n"; }}
else { print "Socket ferme\n"; }

#while ($thread1) { print "Thread ouvert \n"; sleep; }
print "OK";