473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Socked not valid - how to check it?

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
Jul 19 '05 #1
0 1565

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: John V | last post by:
What kind of regular expression pattern is needed to check if URL is valid? It's enought if most of cases are covered. I have PHP 4.x. Br
16
by: siliconmike | last post by:
Hi, I'm looking for a reliable script that would connect to a host and somehow determine whether an email address is valid. since getmxrr() only gets the mx records.. Links/pointers ? Mike
7
by: William Stacey [MVP] | last post by:
Given a day of the month (<=31) how to calculate if that day is valid for all months up to some end date or DateTime.MaxValue? TIA -- William Stacey, MVP
3
by: Gonçalo Boléo | last post by:
Is there any way to check if a string is valid URL? thanks, Gonçalo Boléo
3
by: Chris | last post by:
Hi, In C# I tried to save a file from a generated file name. Just before launching the dialog I check for a valid file name to be sure. There for I used the method ValidateNames from the save...
1
by: illegal.prime | last post by:
Hey all, I have an app, that could take two numbers of any type of numerical type int, long, double, float, uint, ulong, etc. I want to check that the numbers are part of a range that I consider...
17
by: Petyr David | last post by:
Just looking for the simplest. right now my perl script returns an error messge to the user if the date string is invalid. would like to do this before accessing the server. TX
9
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
0
by: Rasheed | last post by:
Hi All, Could any body help me. Regarding how to check a URL is Valid or Invalid. I am using Four functions to check the same. 1) hConnect = WinHttpConnect( hSession, "www.google.co.in",...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.