Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Nonblocking Networking

by flocto (Pilgrim)
on Mar 16, 2002 at 20:28 UTC ( [id://152230]=perlquestion: print w/replies, xml ) Need Help??

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

Hi,
the day has come that my problems became stronger than the concentration of caffeine in my blood, and so I desperately need you help, fellow monks.

Here's the situation: There's a little, nifty (irc) bot, written entirely in perl built upon Net::IRC. Now I was asked to write a plugin for this bot to provide some statistics via an HTTP-connection. So I went to CPAN, found HTTP::Daemon and everything was fine, until I realized that my bot wasn't joining any channels anymore. Now, what happened? The process got stuck in an accept () call. "No problem" was my first though, "a simple fork() and that's it..".. Yeah. that would have been nice, if there wasn't this little problem: How should I get up-to-date information from the main process to generate my statistics?

I thought about using SIGIO for accepting connections as they come, but hardly found any perl-related documentation on this..

I have to admit that I'm not doing this socket-thing very often, so it might be that the solution is darn simple and I'm an idiot, but I just don't see it right now..

Thanks you very much for your patience,
Regards, octo

--
GED/CC d-- s:- a--- C++(+++) UL+++ P++++$ L++>++++ E--- W+++@ N o? K? w-- O- M-(+) V? !PS !PE !Y PGP+(++) t-- 5 X+ R+(+++) tv+(++) b++@ DI+() D+ G++ e->+++ h!++ r+(++) y+

Replies are listed 'Best First'.
Re: Nonblocking Networking
by abstracts (Hermit) on Mar 16, 2002 at 22:50 UTC
    Hello

    Let me summarize your problem. You have an IRC bot (uses Net::IRC) and it has an event loop in which events are fired and handlers are dispatched. HTTP::Daemon also has an event loop and the two event loops do not mix. How do you get both event loops running while still communicating between the processes?

    Here is one simple way: do not run an httpd, instead use an off the shelf web server (apache), and let the bot dump the stats in files accessible by the server. Here the stats won't be real-time, but it might be okay for your application.

    Another way (also simple) is to have a cgi-script (one that provides the stats) use Net::IRC to contact the bot (via DCC perhaps) and pull all the information. This was is still simpler than mixing the processes together, but there is some small overhead as the cgi script needs to contact the bot (kinda IPC through DCC).

    This is all I can think of at the moment to make your life easier. Any other way might be too complicated for an IRC toy.

    Hope this helps,,,

    Aziz,,,

Re: Nonblocking Networking
by hossman (Prior) on Mar 17, 2002 at 05:07 UTC
Re: Nonblocking Networking
by dws (Chancellor) on Mar 16, 2002 at 20:41 UTC
    So I went to CPAN, found HTTP::Daemon and everything was fine, until I realized that my bot wasn't joining any channels anymore.

    How about giving us something more to work with (like some code). Otherwise, we're forced to fill in a lot of the pieces from the meager info you've provided.

    If (and I'm guessing here) you're writing a plugin that needs to make a web request and parse the results, there are, I believe, example plugins to base your work on. The "purl" bot on the old efnet #perl channel had a google plugin. Look through the existing Net::IRC plugins to see if there's already one that does the same thing you're trying to do.

Log In?
Username:
Password:

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

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

    No recent polls found