Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Thanks a lot for your replies.

Sorry, my previous answer was ambiguous: $pid is undefined in the handle_request () method of MyWebServer, but it is correctly set to something like "-1470" in test.pl.

In fact, writing this in test.pl effectively stops the server immediately:
use strict; use warnings; use MyWebServer; my $server = MyWebServer->new(8080); my $pid = $server->background(); kill 9, $pid;

But in order to execute this instruction in response to some HTTP request, (I think) I need to call it from within a handler in MyWebServer.

I find that the following:
kill 9, $$;
effectively stops the server if it is added anywhere in MyWebServer.pm's "body" (e.g. at the first line), but not if it is added in the handle_request() method.

I've also tried tilly's suggestion to have test.pl write the PID in a file, then have handle_request() read this file. It does succeed at passing the PID, and I do not get the "Can't kill a non-numeric process ID" message anymore, however the call to kill does not stop the server in this case.


In reply to Re^6: Stopping an HTTP::Server::Simple server by textual
in thread Stopping an HTTP::Server::Simple server by jaldhar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (9)
As of 2024-04-23 10:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found