Syntactic Confectionery Delight | |
PerlMonks |
Re: IO::Socket *always* making connection?by saskaqueer (Friar) |
on Feb 08, 2005 at 21:55 UTC ( [id://429239]=note: print w/replies, xml ) | Need Help?? |
update: Oops, I wasn't thinking either. My eval/alarm solution will not work because the connection is successfull and therefore it contains the exact same issue as the OP. Sorry. *sigh* In lieu of the completely refactored parent node, here is the refactored answer :) When you set a socket to listen() via IO::Socket::INET, the port will come up as in-use and will queue up successive connection requests. Since your first client that connects is in an infinite loop, the second client to connect is simply waiting for the first client to close the connection to the server. The easiest way to fix such a problem is to set a timeout via a signal handler. Such an example is provided here (see the last paragraph of screen 7 of `perldoc perlipc` on a 24-row terminal for an explanation of the $SIG{ALRM} and alarm()):
Also, you can modify your server code (b.pl) so that you're not recreating the socket for each connection. You can instead move the socket creation outside of the infinite loop and loop on accept():
In Section
Seekers of Perl Wisdom
|
|