baddah has asked for the wisdom of the Perl Monks concerning the following question:
Before my MySocket->send i would like to see that the socket server went down,and this must pass control back to the place where i try to connect.Any suggestions? Thanks#!/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; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Check if Socket is alive before send
by shmem (Chancellor) on Nov 19, 2007 at 15:26 UTC | |
by tye (Sage) on Nov 19, 2007 at 16:55 UTC | |
|
Re: Check if Socket is alive before send
by TOD (Friar) on Nov 20, 2007 at 05:00 UTC |