Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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)
"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?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2018-06-18 04:18 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (107 votes). Check out past polls.