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

IO::Socket question

by MF (Scribe)
on Feb 11, 2004 at 21:29 UTC ( #328389=perlquestion: print w/replies, xml ) Need Help??

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

Hello, fellow monks. I'm trying to learn to use IO::Socket and decided to write a quick SMTP dialogue to get the hang of it. I had it working in this fashion, but I changed something and now Perl just stalls when I run my little program. The static print doesn't even show up, so there must by something wrong with my module call, but I have no idea what. I changed everything around a dozen times and I'm at a loss right now. I'd appreciate any help.
#!/usr/bin/perl use warnings; use strict; use IO::Socket; my $sock = new IO::Socket::INET(PeerAddr => 'x.y.z', PeerPort => '25', Proto => 'tcp',); print "bier"; print $sock "HELO x\n"; print <$sock>; close ($sock);

Replies are listed 'Best First'.
Re: IO::Socket question
by borisz (Canon) on Feb 11, 2004 at 21:58 UTC
    The line print <$sock>; reads all lines until the $sock is closed. I think you want print scalar(<$sock>);
    Boris
      Thanks a million. It works now :) The reason I had it working first is because I initially forgot to close the socket, that printed out the server reply just dandy.
Re: IO::Socket question
by Abigail-II (Bishop) on Feb 11, 2004 at 22:20 UTC
    Ah, the joys of socket programming. You've caused a deadlock situation. The <sock> makes that your program is waiting for input (it's going to suck up all the input until eof, which in this case means, the socket closing). But the other end is also waiting for input, and it's not going to talk until it sees something. Your program is only going to finish if the other ends break the deadlock because some timer goes off.

    Abigail

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2021-03-03 20:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (92 votes). Check out past polls.

    Notices?