According to the pod,

If Listen is defined then a listen socket is created, else if the socket type, which is derived from the protocol, is SOCK_STREAM then connect() is called.

but when I run the code in the first anon block below, absolutely nothing happens. No errors are returned, an IO::Socket handle is returned (see the output below), but neither my firewall nor my packet sniffer show any activity whatsoever. (AS 5.6.1 and/or AS 5.8 under NT4/sp6a)

The second anon block uses Socket.pm to connect, write and read from the same host:port and works fine. I see everything go through the sniffer.

What is wrong with the first block of code?

#! perl -slw use strict; { use IO::Socket::INET; my %socket = ( Host=>'www.perl.org', Port=>80, Proto=>'tcp', Timeout=>10, Type=>SOCK_STREAM ); my $socket = IO::Socket::INET->new(%socket) or die $!; print $socket; close $socket or die $!; print 'IO::Socket::INET closed'; } { use Socket; select STDOUT; print 'About to open socket'; socket(SH, PF_INET, SOCK_STREAM, getprotobyname('tcp')) or die $!; print 'socket opened'; my $dest = sockaddr_in(80, inet_aton('www.perl.org')); connect(SH, $dest) or die $!; print 'connected'; select SH; $|=1; print SH 'GET / HTTP/1.0' . "\cM\cJ\cM\cJ" or die $!; select STDOUT; print 'sent'; print <SH> or die $!; print 'received'; }

Output

D:\Perl\test>test IO::Socket::INET=GLOB(0x1c19ce8) IO::Socket::INET closed About to open socket socket opened connected sent HTTP/1.1 200 OK Date: Thu, 24 Apr 2003 05:00:15 GMT Server: Apache/2.0.44-dev (Unix) DAV/2 Last-Modified: Wed, 16 Apr 2003 15:55:53 GMT ETag: "6fcce-3-95229440" Accept-Ranges: bytes Content-Length: 3 Connection: close Content-Type: text/html; charset=ISO-8859-1 x2 received

Examine what is said, not who speaks.
1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
3) Any sufficiently advanced technology is indistinguishable from magic.
Arthur C. Clarke.

In reply to IO::Socket:INET doesn't attempt to connect by BrowserUk

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.