#!/usr/local/bin/perl use threads; use IO::Socket::INET; $error=1; my $MySocket; while (1) { if ($error eq 1) { if ($MySocket=new IO::Socket::INET->new(PeerPort=>1234,Proto=>'tcp',PeerAddr=>'192.168.100.9')) { $error=0; print "Connected $error \n"; } else { print "Could not connect try again 5ms \n"; select(undef, undef, undef, 0.5); $error=1; } } else { print "Hallo daar Error=$error\n"; $thread1 = threads->new(\&sendQMsg); $thread2 = threads->new(\&sendQMsg2); grep {$_->join;} ($thread1,$thread2); while ( my(@list)=threads->list()) { print "$#list\n"; grep { $_->join } @list; } } } sub sendQMsg { $message = "Hi from thread 1"; if ($MySocket->send($message)) { $error=0; } else { $error=1; } } sub sendQMsg2 { $message = "Hi from thread 2\n"; if ($MySocket->send($message)) { $error=0; } else { $error=1; } }