Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Problem with example UDP script from Perl Little Black Book

by kyser_sose (Initiate)
on Feb 02, 2002 at 17:10 UTC ( [id://142937]=perlquestion: print w/replies, xml ) Need Help??

kyser_sose has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to run an example script out the Perl little black book and its not going very well.
#!/usr/bin/perl use IO::Socket; $socket = IO::Socket::INET->new(Proto => 'udp', peerPort => 4321, peeraddr => localhost); $socket->send('Hello');
I get the following error msg.
send:cannot determine peer address at line 6
I've tried changing peer to local and for the address using the output from hostname --fqdn

Please help!
Thanks
another Newbie

Replies are listed 'Best First'.
Re: what the?
by wog (Curate) on Feb 02, 2002 at 17:38 UTC
    IO::Socket:INET is case-sensitive, so you must use PeerPort and PeerAddr, not peerPort and peeraddr.

    Though, it won't solve your problem in this case, I strongly advise quoting strings and using strict and warnings. It is likely to save you time in the future.

Re: what the?
by data64 (Chaplain) on Feb 02, 2002 at 17:27 UTC

    You probably want to include a

    use strict; use warnings;

    at the top.

    I would guess the problem is that localhost should be enclosed in quotes like "localhost".

    Update: Added working code.

    Below is code that works for me.

    #!/usr/bin/perl.exe use IO::Socket; use strict; use warnings; my $socket; $socket = IO::Socket::INET->new(Proto => 'udp', PeerPort => 80, PeerAddr => "localhost") or die "opening port, $! "; $socket->send("Hello");
Re: what the?
by LukeyBoy (Friar) on Feb 02, 2002 at 17:34 UTC
    Instead of "peeraddr => localhost" you should use:

    $socket = IO::Socket::INET->new(Proto => 'udp', PeerAddr => "localhost:4321");

    That should work.
Re: Problem with example UDP script from Perl Little Black Book
by kyser_sose (Initiate) on Feb 02, 2002 at 23:45 UTC
    Thanks for all the answers :) Using the correct letter casing seemed to fix that particular prob. Thanks agian.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://142937]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-20 13:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found