BrowserUk has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: IO::Socket:INET doesn't attempt to connect
by merlyn (Sage) on Apr 24, 2003 at 05:44 UTC | |
by BrowserUk (Patriarch) on Apr 24, 2003 at 05:58 UTC | |
|
Re: IO::Socket:INET doesn't attempt to connect
by Zaxo (Archbishop) on Apr 24, 2003 at 05:44 UTC | |
by BrowserUk (Patriarch) on Apr 24, 2003 at 06:01 UTC |