You said that you already have a cycle of events in the first tier. In a sense, your second-level server should also organize some kind of event loop for asynchronous processing. There are many ways to encode it with perl, for example AnyEvent , POE , Event , to name just a few. In the end, they all use one of the OS components select , poll , epoll , kqueue (or their Windows equivalent). If you feel comfortable coding at a relatively low level, you can simply use the perl select built-in or, alternatively, its object-oriented analogue IO::Select .
Basically, you create two sockets for listening (you may need only one if the first level uses the same communication protocol as the third level to talk to your server), add it to the IO::Select object and make a selection on it. After connecting, you add the received sockets to the selected object. The select method IO::Select will provide you with a list of sockets ready to be read or written (I ignore the possibility of exceptions here). Of course, you have to keep track of your sockets to find out which one. In addition, the communication logic will be somewhat complicated, because you have to use non-blocking sockets.
As for the second part of your question, I'm a little confused about what you mean by “cgi” - whether it is a common gateway interface (ie server side web scripts) or is it short for “computer graphics”. In both cases, I think it makes sense to use a push server for your task. In the latter case, all that I would like to say. In the first case, I offer you google for "Comet" (as in "AJAX"). :-)
Grrrr source share