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>);
      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.