Use setsockopt and set the option SO_REUSEADDR:
use Socket;
...
setsockopt(SOCK, SOL_SOCKET, SO_REUSEADDR) or
warn "OOPS, setsockopt failed $!\n";
HTH, --traveler
| [reply] [d/l] [select] |
I used to solve this problem in C using setsockopt(2), with the option SO_REUSEADDR. It basically tells the system that it's OK to bind to a port as long as no one is listening to the same port.
In Perl you can say:
setsockopt(YOURSOCKET, SOL_SOCKET, SO_REUSEADDR, 1) or die "your messa
+ge\n";
-- TMTOWTDI | [reply] [d/l] [select] |
my $server = IO::Socket::INET->new(....);
setsockopt($server, SOL_SOCKET, SO_REUSEADDR, 1);
$server doesn't exist until after the bind, but the bind won't happen (and perl will stop) at the ->new() because the port is already "taken"...
I'm quite sure I'm so far off base you're laughing - which is fine - as long as you can tell me how its _supposed_ to work :)
Thanks,
JP
-- Alexander Widdlemouse undid his bellybutton and his bum dropped off -- | [reply] [d/l] |
setsockopt can be used immediately after calling socket and before bind, if using the functional socket interface.
With perldoc IO::Socket you can easily find out that all you need to do is passing the Reuse option to your constructor:
my $server = IO::Socket::INET->new(...., Reuse => 1);
Happy recycling!
-- TMTOWTDI | [reply] [d/l] [select] |