Home > Archive > PERL Miscellaneous > November 2005 > Socket programming muddle
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Socket programming muddle
|
|
|
| This innocent looking piece of code is suppose to grab a webpage from a
url.
When the script is executed, "use of uninitialized value in print ... "
I've checked my creation of the peer connection with several scripts
and web resources.
I could not notice much differences. However, I am pretty sure that the
fault lies with the
peer connection. The GET command works on telnet and I've ran out of
ideas of where I could
screw up.
Please shed some light on this murky issue, your input are much
appreciated.
=======
#!/usr/bin/perl -w
use Carp;
use Socket;
$file = "www.cs.mu.oz.au/~mwql/index.php";
$add = $1, $file_l = $2 if ($file =~ m#([^/]+)([/].*)#);
$port = 80;
$proto = getprotobyname ('tcp');
print "$add $file_l $port $proto\n";
# Create stream socket
# Get IP address of peer
socket (SOCKET, PF_INET, SOCK_STREAM, $proto) or die "socket not made";
$iadd = inet_aton ($add);
# Get local socket address
# Bind it to our socket
$temp = sockaddr_in (0, INADDR_ANY);
bind (SOCKET, $temp) or die "bind unsuccessful";
# Pack IP address of the peer with the port
# Connect to the peer
$ads = sockaddr_in ($port, $iadd);
connect (SOCKET, $ads) or die "connect unsuccessful";
# Send a sample request
# Receive a initial response
print SOCKET <<"yahoo";
HEAD $file_l HTTP/1.0\r\n
\r\n
yahoo
$cur = <SOCKET>;
print $cur;
=======
| |
| John Bokma 2005-11-26, 3:58 am |
| "mwql" <mwql.aus@gmail.com> wrote:
> This innocent looking piece
has been posted before.
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
I ploink googlegroups.com :-)
| |
|
| =======
#!/usr/bin/perl -w
use strict;
use warnings;
use Carp;
use Socket;
my ($file_l, $file, $add, $port, $proto, $iadd, $temp, $ads, $cur);
$file = "www.cs.mu.oz.au/~mwql/index.php";
$add = $1, $file_l = $2 if ($file =~ m#([^/]+)([/].*)#);
$port = 80;
$proto = getprotobyname ('tcp');
print "$add $file_l $port $proto\n";
# Create stream socket
# Get IP address of peer
socket (SOCKET, PF_INET, SOCK_STREAM, $proto) or die "socket not made";
$iadd = inet_aton ($add);
# Get local socket address
# Bind it to our socket
$temp = sockaddr_in (0, INADDR_ANY);
bind (SOCKET, $temp) or die "bind unsuccessful";
# Pack IP address of the peer with the port
# Connect to the peer
$ads = sockaddr_in ($port, $iadd);
connect (SOCKET, $ads) or die "connect unsuccessful";
# Send a sample request
# Receive a initial response
print SOCKET <<"yahoo";
HEAD $file_l HTTP/1.0\r\n
\r\n
yahoo
$cur = <SOCKET>;
print $cur;
=======
"Use of uninitialized value in print at perl/nget/nget.pl line 43."
Yeah, I cannot use LWP or IO::Socket, because those packages are not
available to me and I do not have root permissions. The second post was
made because google didn't update my first post quickly enough, and I
assumed that something screwed up along the way.
Use strict and use warnings did not help with my problem, unfortunately.
| |
| RedGrittyBrick 2005-11-27, 6:58 pm |
| mwql wrote:
<snip: broken code>
>
> "Use of uninitialized value in print at perl/nget/nget.pl line 43."
>
> Yeah, I cannot use LWP or IO::Socket, because those packages are not
> available to me and I do not have root permissions.
perldoc -q "my own module"
|
|
|
|
|