Socked not valid - how to check it?

Discussion in 'Perl Misc' started by Tomasz Judycki, Mar 3, 2004.

  1. 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
     
    Tomasz Judycki, Mar 3, 2004
    #1
    1. Advertising

  2. Tomasz Judycki <> wrote:
    > 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.

    *snip*

    Consider SO_KEEPALIVE.. problem is it's meant for connections that
    last a little longer..

    $socket->sockopt(SO_KEEPALIVE, 1);


    If they're on the same host you can check PIDs via written record
    file or direct query. I doubt that's your end-state though..

    Cheers, -Ali

    --
    Was I helpful?: http://svcs.affero.net/rm.php?r=packetknife
    --
    Any sufficiently advanced technology is indistinguishable from
    magic. -- Arthur C. Clarke
     
    Ali-Reza Anghaie, Mar 3, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tomasz Judycki

    Socked not valid - how to check it?

    Tomasz Judycki, Mar 3, 2004, in forum: Perl
    Replies:
    0
    Views:
    494
    Tomasz Judycki
    Mar 3, 2004
  2. Shapper
    Replies:
    4
    Views:
    9,356
    leotiger
    Sep 20, 2006
  3. G Fernandes
    Replies:
    9
    Views:
    627
    DHOLLINGSWORTH2
    Feb 27, 2005
  4. Raymond Chiu

    how to check a date is valid or not

    Raymond Chiu, Oct 4, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    816
    Graeme Bradbury
    Oct 4, 2007
  5. luca72

    socked and bytes operation

    luca72, Apr 21, 2010, in forum: Python
    Replies:
    4
    Views:
    410
    luca72
    Apr 24, 2010
Loading...

Share This Page