Socket programming muddle

Discussion in 'Perl Misc' started by mwql, Nov 26, 2005.

  1. mwql

    mwql Guest

    The script waits, during execution, and after a while, it prints:
    "Use of uninitialized value in print ..."

    I am pretty sure I screwed up setting up the peer connection. I
    tried the GET command on telnet and it works fine. When I checked
    through several resources, it seems that I am setting up the connection
    according to the rules.

    I ran another similar-url-get script, had a quick browse through
    the socket connection set up, they didnt differ from mine alot.

    =============

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

    =============
     
    mwql, Nov 26, 2005
    #1
    1. Advertising

  2. mwql

    John Bokma Guest

    "mwql" <> wrote:

    > The script waits, during execution, and after a while, it prints:
    > "Use of uninitialized value in print ..."


    Always give a complete message, and indicate the line nr below.

    >
    > I am pretty sure I screwed up setting up the peer connection. I
    > tried the GET command on telnet and it works fine. When I checked
    > through several resources, it seems that I am setting up the connection
    > according to the rules.
    >
    > I ran another similar-url-get script, had a quick browse through
    > the socket connection set up, they didnt differ from mine alot.


    Why don't you use LWP?

    (And why no use strict; use warnings; ?)

    --
    John Small Perl scripts: http://johnbokma.com/perl/
    Perl programmer available: http://castleamber.com/
    I ploink googlegroups.com :)
     
    John Bokma, Nov 26, 2005
    #2
    1. Advertising

  3. John Bokma wrote:
    > "mwql" <> wrote:
    >>The script waits, during execution, and after a while, it prints:
    >>"Use of uninitialized value in print ..."


    <snip>

    > (And why no use strict; use warnings; ?)


    Warnings were enabled (via the -w switch), or else the uninitialized
    warning wouldn't have shown up. (But strictures would have been nice...)

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Nov 26, 2005
    #3
  4. mwql

    John Bokma Guest

    Gunnar Hjalmarsson <> wrote:

    > John Bokma wrote:
    >> "mwql" <> wrote:
    >>>The script waits, during execution, and after a while, it prints:
    >>>"Use of uninitialized value in print ..."

    >
    > <snip>
    >
    >> (And why no use strict; use warnings; ?)

    >
    > Warnings were enabled (via the -w switch),


    Yup, saw that, but: why not use warnings; ;-)

    --
    John Small Perl scripts: http://johnbokma.com/perl/
    Perl programmer available: http://castleamber.com/
    I ploink googlegroups.com :)
     
    John Bokma, Nov 26, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kj
    Replies:
    25
    Views:
    1,142
    Patrick TJ McPhee
    Apr 19, 2004
  2. Laszlo Nagy
    Replies:
    1
    Views:
    5,084
    Mark Wooding
    Jan 27, 2009
  3. Jean-Paul Calderone
    Replies:
    0
    Views:
    1,027
    Jean-Paul Calderone
    Jan 27, 2009
  4. Laszlo Nagy
    Replies:
    0
    Views:
    594
    Laszlo Nagy
    Feb 1, 2009
  5. mwql

    Socket programming muddle

    mwql, Nov 26, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    130
    RedGrittyBrick
    Nov 27, 2005
Loading...

Share This Page