I am writing a program that scans through a list of servers that i have and connects to them all one by one to make sure that they are valid servers, however if i happen to pass over a telnet server, my program hangs up during the handshaking process. Normally, i would go ahead and have the program complete the whole handshaking process but since it's uneccessary for this particular program i'd rather not do that if possible, i've tried different ways of making the connection timeout all to no avail, here's some of the code i'm using to make the connection. Any ideas would be very much appreciated.

shortened for brevity:
-------------------------------------------------

&connect_host; send(SOCKET,$begin, 0); while (defined($_ = <SOCKET>)) { if ($_ =~ /3point\>/ig){ $valid = 1; close SOCKET; } else { $valid = 0; close SOCKET; } } if ($valid == 1){ print "valid server\n"; } else { print "invalid server\n"; } sub connect_host{ $iaddr = inet_aton($host) or die "ERROR1: $!\n"; $port = sockaddr_in($port, $iaddr) or die "ERROR2: $!\n"; $proto = getprotobyname('tcp') or die "ERROR3: $!\n"; socket(SOCKET, PF_INET, SOCK_STREAM, $proto) or die "ERROR4: $!\n"; connect(SOCKET, $port) or die "ERROR5: $!\n"; }
---------

:|

Edit: chipmunk 2001-05-17


In reply to Telnet handshaking by rq-2102

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.