Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Problems with IO::Socket and recv

by dooberwah (Pilgrim)
on Jun 05, 2002 at 16:30 UTC ( #171894=perlquestion: print w/replies, xml ) Need Help??
dooberwah has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to learn some basic network communications using the IO module. After reading the man pages for IO::Socket and IO::Select I wrote the following test script:

#!/usr/bin/perl -w use strict; use IO::Socket; use IO::Select; my $s = IO::Select->new(); $s->add(\*STDIN); my $foo; my $msg; $s->can_read(); foreach $foo ( $s->can_read() ){ $foo->recv($msg, 1024, 0); print "$msg\n"; }

To me, this looks like it should work fine, but instead of running smoothly it produces this error message:
Can't locate object method "recv" via package "IO::Handle" (perhaps you forgot to load "IO::Handle"?)

Now, I didn't load IO::Handle, because I didn't need any of the functions from it directly. I realize that IO::Socket inherits from IO::Handle, but shouldn't that just take care of itself behind the scenes?

-Ben Jacobs (dooberwah)
http://dooberwah.perlmonk.org
"one thing i can tell you is you got to be free"

Edit: Added <code> tags. larsen

Replies are listed 'Best First'.
Re: Problems with IO::Socket and recv
by Aristotle (Chancellor) on Jun 05, 2002 at 16:58 UTC
    Substitute sysread $foo, $msg, 1024;
    for $foo->recv($msg, 1024, 0);
    What you're reading from is not a socket, so it's not autovivified to a socket and conversely the object it becomes does not know recv.

    Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://171894]
Approved by Rex(Wrecks)
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2017-11-19 07:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (278 votes). Check out past polls.

    Notices?