My typo. This: my $sel = IO::Socket->new( $socket ); should have been: my $sel = IO::Select->new( $socket );.

Try this:

#!perl -w use strict; use IO::Socket::INET; use IO::Select; my $channel_id = open_channel("127.0.0.1", "7777"); sub open_channel { # create a connecting socket my $host = shift; my $port = shift; my $timeout = 5; if ( $host !~ m/(\d+)\.(\d+)\.(\d+).(\d+)/i ) { print "IP Address:'$host' is not a Valid IP-Address."; return 139; } my $socket = new IO::Socket::INET ( PeerHost => $host, PeerPort => $port, Proto => 'tcp', ); die "cannot connect to the server $!\n" unless $socket; my $sel = IO::Select->new( $socket ); if ( !defined $socket ) { print "Opening TCP Channel to host: $host and Port: $port Fail +ed !!"; return 138; } else { $socket->send("Check Connectivity"); while (1) { my @ready = $sel->can_read( $timeout ) or do{ print "=> Time-Out as no data received for '$timeo +ut sec'.!!\n"; last; }; my $recieved_data= <$socket>; if ( defined $recieved_data ) { chomp($recieved_data); if ($recieved_data =~ /Connected to TCP socket server/ +i){ print "TCP Connection established with Channel id: + '$socket'\n"; return $socket; } else{ print "Cannot craete connection with server\n"; return 137; } } } $socket->close(); } }

Note: this is still untested code. The idea is that you should look at the docs for IO::Select and try to understand what the above code is suggesting.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^3: alarm not working on windows machine by BrowserUk
in thread alarm not working on windows machine by Rahul Gupta

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.