Socked not valid - how to check it?

T

Tomasz Judycki

Hi all!

I've got a problem - probably easy to solve but I practically don't know Perl
nor modules so it's hard for me.

The problem concerns two processes communicating via sockets. I need to know
that one of them died already and there is no point in sending anything to it.

This is a script iris_s.pl acting as server :
===========================================
#!/usr/bin/perl

use IO::Socket;
use IO::Select;

# Start the RAD server
$server = new IO::Socket::INET(Listen => 10,
LocalPort => 2350,
Reuse => 1)
or die "Could not establish a server\n";

print "Server started\n";

$client = $server->accept();
$message = <$client>;
push (@IrisReq, $client);
print "slepping for 10 seconds\n";
sleep 10;
$IrisPort = shift @IrisReq;
if ((@ready = IO::Select->new($IrisPort)->can_write(0))) {
print "Can write\n";
} else {
print "Can NOT write\n";
}
sleep 5;
$IrisPort->close;
===========================================

This is a script iris.pl that sends request to iris_s.pl and waits for an
answer but after 5 seconds finishes execution:

===========================================
#!/usr/bin/perl

#binmode(STDIN);
#binmode(STDOUT);
#binmode(STDERR);

use IO::Socket;
use IO::Select;

unless($sock = IO::Socket::INET->new("localhost:2350")) {
print "NoRadErr\n";
}

$sock->autoflush(1);

$sel = IO::Select->new();
$sel->add($sock);

print $sock "Iris: Req \n";

print "Waiting for 5 seconds\n";

@ready = $sel->can_read(5);

if (@ready) {
chomp($RexPort = <$sock>);
} else {
print "RadTimeoutErr\n";
}

$sock->close;
$sel->remove($sock);
===========================================

Testing : start iris_s.pl and then iris.pl. Finally iris_s.pl will print 'Can
write'.

How can I check in iris_s.pl that iris.pl died already? Or: what should I do
in iris.pl to let iris_s.pl know that socked is closed?

Please be descriptive as I'm far from being Perl expert.

Regards,

Tomasz Judycki

Textus Virtualis Sp. z o.o.
Szaserów 3
04-293 Warszawa
tel/fax (48 22) 879 82 00
http://www.tv.com.pl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top