Beefy Boxes and Bandwidth Generously Provided by pair Networks Ovid
The stupid question is the question not asked
 
PerlMonks  

Re: Perl Sockets Problem

by cbro (Pilgrim)
on Jul 07, 2003 at 21:40 UTC ( #272117=note: print w/ replies, xml ) Need Help??


in reply to Perl Sockets Problem

Your client is fine (and most of your 'server' too).
Using Data::Dumper, I very quickly found out that $storage (actually $_) is not defined the way you tried. Why don't you try something like this:

my $new_sock = $sock->accept(); while (my $storage = <$new_sock>) { print $storage . "\n"; $new_sock = $sock->accept(); } close($sock);
That will give you a loop until you manually kill the script. If you just want to receive one message then take out the $new_sock = $sock->accept() that's inside the while loop. If you want to keep the socket open for multiple messages, but also want to make sure the socket is cleanly closed (which my above example does not do). Write a SIG handler that makes sure the socket gets closed upon receiving a SIGHUP, SIGTERM, etc.
HTH,
Chris


Comment on Re: Perl Sockets Problem
Select or Download Code
Re: Re: Perl Sockets Problem
by JoeJaz (Monk) on Jul 10, 2003 at 15:57 UTC
    Thanks! That looks like a good way to keep a continuous connection open between the two hosts. This should be very helpful for my application. I intend to use perl to fork off processes in a cluster. Looks like sockets has some good potential. Thanks again.
    Joe

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (10)
As of 2014-04-25 08:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (585 votes), past polls