Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

IO::Socket question

by MF (Scribe)
on Feb 11, 2004 at 21:29 UTC ( [id://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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-03-28 15:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found