Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 864149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:25:42+00:00 2026-05-15T09:25:42+00:00

I have a basic perl HTTP server using HTTP::Daemon . When I stop and

  • 0

I have a basic perl HTTP server using HTTP::Daemon. When I stop and start the script, it appears that the port is still being listened on and I get an error message saying that my HTTP::Daemon instance is undefined. If I try to start the script about a minute after it has stopped, it works fine and can bind to the port again.

Is there any way to stop listening on the port when the program terminates instead of having to wait for it to timeout?

 use HTTP::Daemon;
 use HTTP::Status;

 my $d = new HTTP::Daemon(LocalAddr => 'localhost', LocalPort => 8000);

 while (my $c = $d->accept) {
    while (my $r = $c->get_request) {
       $c->send_error(RC_FORBIDDEN)
    }
    $c->close;
    undef($c);
 }

EDIT:

As per DVK’s response, I tried calling $d->close() but am still getting the same error when trying to restart my script.

END { $d->close(); }
$SIG{'INT'} = 'CLEANUP';
$SIG{__WARN__} = 'CLEANUP';
$SIG{__DIE__} = 'CLEANUP';

sub CLEANUP {
    $d->close();
    undef($d);
    print "\n\nCaught Interrupt (^C), Aborting\n";
    exit(1);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T09:25:42+00:00Added an answer on May 15, 2026 at 9:25 am

    I found a solution to my problem by setting ReuseAddr => 1 when creating the HTTP::Daemon.

    my $d = new HTTP::Daemon(
        ReuseAddr => 1, 
        LocalAddr => 'localhost', 
        LocalPort => 8000);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have been using Perl's Net:Twitter CPAN module (version 3.12) and basic authentication (not
This may be a basic question. I have written a small perl script to
I have a perl script that I need to tweak. The script runs and
I have a basic web service that returns the following object as JSON: public
How can I use HTTP basic Authentication and have the user submit their Username
I have an application that is being expanded to the UK and I will
I have a wcf service set up to accept basic http binding. I want
I have created a basic flash socket server in PHP, it all works fine
I have a question that seems basic, but I can't figure out. Say that
I am a beginner to Perl syntax and have a basic wildcard question. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.