Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Daemons in Perl

by sawanv (Novice)
on Jan 15, 2003 at 09:03 UTC ( [id://227091]=perlquestion: print w/replies, xml ) Need Help??

sawanv has asked for the wisdom of the Perl Monks concerning the following question:

Hello All. Can anyone give me a few pointers for writing a daemon in Perl? Something that listens on some port and replies to some requests made via sockets. What stuff do I need to know (functions, libraries, modules, packages etc)? Hints, tips, URLs, welcome. Thanks Sawan

Replies are listed 'Best First'.
Re: Daemons in Perl
by IlyaM (Parson) on Jan 15, 2003 at 09:13 UTC
Re: Daemons in Perl
by dws (Chancellor) on Jan 15, 2003 at 09:16 UTC
    Can anyone give me a few pointers for writing a daemon in Perl? Something that listens on some port and replies to some requests made via sockets. What stuff do I need to know (functions, libraries, modules, packages etc)?

    Linconl Stein's Network Programming with Perl covers everything you need to know.

    A careful study of HTTP::Daemon will also be rewarding.

    Try a Super Search for "Daemon".

Re: Daemons in Perl
by herveus (Prior) on Jan 15, 2003 at 12:19 UTC
    Howdy!

    Net::Server also provides a flexible framework for writing servers. I found it to be straightforward to use.

    Now, you say you are looking for a daemon, but then describe a server. The two are not exactly the same thing in my mind. A daemon does not necessarily listen on ports; it may be doing other tasks (useful or useless, as it may be) that are strictly local to the machine. A server listening on a port can be a special case of a daemon.

    yours,
    Michael

Re: Daemons in Perl
by mce (Curate) on Jan 15, 2003 at 13:42 UTC
    The cookbook chapter 17 should get you started.
    ---------------------------
    Dr. Mark Ceulemans
    Senior Consultant
    IT Masters, Belgium
Re: Daemons in Perl
by castaway (Parson) on Jan 15, 2003 at 09:42 UTC
    $sockserv = new IO::Socket::INET( LocalAddr => '192.168.1.1', LocalPort => $port, Proto => 'tcp', Listen => 1, Reuse => 1, Timeout => 60); die "can't start server: ($!)\n" unless $sockserv; $x = IO::Select->new(); $x->add($sockserv); while(1) { @handles = $x->can_read(); foreach $handle (@handles) { if($handle == $sockserv) { $sockclient = $sockserv->accept() || warn "accept: $!"; $clients++; if ($clients > 5) { print $sockclient "Sorry, we're full.\n"; $sockclient->close(); } else { $sockclients[$clients] = $sockclient; } $x->add($sockclients[$clients]); } ($cl) = grep($sockclients[$_] == $handle, (0..$#sockclients)); if ($cl) { $n_read = sysread($sockclients[$cl], $buf, 1024); return 0 if (!n_read || !length $buf); parse_external_command($buf, $sockclients[$cl]); } } }
    something like that.. where parse_external_command() reads what the client said, and answers via the passed in socket if necessary.
    C.
      Hmm, I'm missing a:
      die "can't start server: ($!)\n" unless $blah;
      in there.
      C.
Re: Daemons in Perl
by defyance (Curate) on Jan 15, 2003 at 19:30 UTC
    You could also have a look at Proc::Deamon for some ideas. I've found it to be useful in the past.

    -- Can't never could do anything, so give me and inch, I'll make it a mile.

Re: Daemons in Perl
by Marza (Vicar) on Jan 15, 2003 at 20:04 UTC

    There is Dave Roths Win32::Daemon I have not tried it myself, but I have been happy with his other stuff.

      Hello all. Thanks for you help and postings all. Sorry for confusion over daemon and server..forgive a newbie. Will check out all your tips. Sawan

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://227091]
Approved by grinder
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-19 17:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found