Stamm has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
I'm trying to play with timeouts in the module IO::Socket. Here's what I got so far.
server.pl:
use 5.010; use strict; use warnings; use IO::Socket; say 'Server listening...'; my $server = IO::Socket::INET->new(Proto => 'tcp', LocalPort => 8000, Listen => 1, ReuseAddr => 1, Timeout => 10) or die; my $client = $server->accept() or die; $server->close; say 'Connection from ' . $client->peerhost;
client.pl:
use 5.010; use strict; use warnings; use IO::Socket; my $socket = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => 'localhost', PeerPort => 8000, Timeout => 10) or die; say 'Client connected';
I launch server.pl, followed shortly by client.pl. I got on the server side:
Server listening... Connection from 127.0.0.1
And on the client side:
Client connectedNow, I launch only server.pl. I got 10 seconds later:
Server listening... accept: timeout ...propagated at server.pl line 16.
So far, so good. Now I launch only client.pl. And I instantly got:
IO::Socket::INET: connect: 10061 ...propagated at client.pl line 8.I would have preferred that the client gave up after 10 seconds.
Is there a way to make the client wait a bit for the server to start up instead of giving up immediately? (I'm on Windows by the way)
Stamm
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Timeouts in IO::Socket (updated)
by haukex (Archbishop) on Jun 23, 2019 at 13:14 UTC | |
by Stamm (Sexton) on Jun 23, 2019 at 15:12 UTC |