Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

The easiest way I can think of is to use the Msg.pm module from Advanced Perl Programming (it's in the Networking directory).

In your running process you would put the listener code (ok, so it's more of a server), i.e.:

use Msg; use strict; my $host = 'localhost'; my $port = 8080; Msg->new_server($host, $port, \&login_proc); print "Server created. Waiting for events"; Msg->event_loop(); #--------------------------------------------------------------- sub login_proc { # Unconditionally accept an incoming connection request return \&rcvd_msg_from_client; } sub rcvd_msg_from_client { my ($conn, $msg, $err) = @_; if (defined $msg) { print "$msg\n"; } }

From the text, "The script calls new_server to create a listening socket (the program's network address) and then calls event_loop, an event dispatcher, which is a thin wrapper over select."

And the client code that would send a message to your running process (server):

use Msg; $conn = Msg->connect('localhost', 8080); die "Error: Could not connect\n" unless $conn; $conn->send_now("Message $i"); ($msg, $err) = $conn->rcv_now();

Use the server and client scripts from the book's example code because the code here is for illustrative purposes.

--
hiseldl
What time is it? It's Camel Time!


In reply to Re: How can I alert perl to a file write by hiseldl
in thread How can I alert perl to a file write by Anonymous Monk

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 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? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2022-06-30 20:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (98 votes). Check out past polls.

    Notices?