Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Socket programming muddle

Reply
Thread Tools

Socket programming muddle

 
 
mwql
Guest
Posts: n/a
 
      11-26-2005
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;

=======

 
Reply With Quote
 
 
 
 
John Bokma
Guest
Posts: n/a
 
      11-26-2005
"mwql" <> 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

 
Reply With Quote
 
 
 
 
mwql
Guest
Posts: n/a
 
      11-27-2005
=======

#!/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.

 
Reply With Quote
 
RedGrittyBrick
Guest
Posts: n/a
 
      11-27-2005
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"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 0 02-01-2009 07:37 AM
socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 1 01-27-2009 05:05 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48,'Address already in use') Jean-Paul Calderone Python 0 01-27-2009 01:41 PM
Socket programming muddle mwql Perl Misc 3 11-26-2005 03:46 AM
Help! Namespace muddle kj XML 25 04-18-2004 11:03 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57