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

I need your help with POE.

My problem is this: My software is doing some TCP-Proxying with VNC-Connections as part of a larger system. Clients are web-based.

To tell the truth, i hacked the whole web based VNC subsystem together in a few days when our main remote control server (used by external partners) finally broke down. Worked like a charm for two years now. But the code is a mess and i'm in the middle of cleaning it up and streamlining it.

For HTML4 + Java Applet i'm currently doing this (grabbed it from PerlMonks if memory serves correctly):

use POE; use POE::Filter::Stream; use POE::Filter::Line; use POE::Component::Proxy::TCP; print "Starting proxy for " . $ARGV[0] . " at port " . $ARGV[1] . "\n" +; $|++; $0 = "vnctunnel " . $ARGV[0] . " source port " . $ARGV[1]; POE::Component::Proxy::TCP->new (Alias => "ProxyServerSessionAlias", Port => $ARGV[1], OrigPort => 5900, OrigAddress => $ARGV[0], # DataFromClient => sub {print "From client:", shift(), "\n";}, # DataFromServer => sub {print "From server:", shift(), "\n";}, RemoteClientFilter => "POE::Filter::Stream", RemoteServerOutputFilter => "POE::Filter::Stream", RemoteServerInputFilter => "POE::Filter::Stream" ); $poe_kernel->run(); exit 0

For HTML5 i'm using NoVNC and the included Python-script to make a websocket proxy.

What i want to do is unify all functionality into a single Perl script and call it with an additional argument to say which HTML-Version the client uses). This way i could streamline my master process big time. And i wont have Python code in my Perl project that i don't even know how to debug.

For the last few days i been scratching my head, reading documentation and seemingly trying to break the world record in facepalms per hours.

I found Protocol::WebSocket and it comes with a simple POE example script, though not a proxy.

Problem is, i also found out that i can't wrap my head around how POE works. Drew a complete blank. Writers block. Whatever... (insert facepalm here)

Can anybody help me? Please?

"You have reached the Monastery. All our helpdesk monks are busy at the moment. Please press "1" to instantly donate 10 currency units for a good cause or press "2" to hang up. Or you can dial "12" to get connected directly to second level support."

Replies are listed 'Best First'.
Re: POE and Websockets
by rcaputo (Chaplain) on Jun 24, 2012 at 21:47 UTC

    There are probably more topical resources for POE help, like POE's mailing list or irc.perl.org channel #poe, depending whether you prefer long-form answers or quicker, specific assistance. There's also POE's wiki, which includes this introductory article and a Cookbook with several examples.

    POE is a callback-based event reactor. When something happens, such as when data appears on a socket, POE's Kernel notifies your code that it can safely read from the socket. POE::Kernel's API hides the details of several event loops, including low-level loops like Ev, and high-level graphical toolkits like Prima.

    POE's callback model may be confusing because it's name-based rather than code-reference based. Named events make certain things easier, like mapping events to any kind of callback, and dynamically loading or reloading callbacks as needed. Some people store their objects in a database and load them (or reload them) as needed. Most people don't use the feature, though.

    POE::Session objects do a few different things, but they mainly act as namespaces for events. Multiple parts of a program can use the same event names, as long as each has a separate session. For example, multiple classes might use the same event name. It would be bad if they got each others' callbacks.

    That's a very basic, very high level synopsis of the two main POE classes. If you have more specific questions, I'll be happy to try answering them.

      Thanks! Very good information, now i know at least what i'm looking for.. and where i'll be able to look for answers ;-)

      "You have reached the Monastery. All our helpdesk monks are busy at the moment. Please press "1" to instantly donate 10 currency units for a good cause or press "2" to hang up. Or you can dial "12" to get connected directly to second level support."
Re: POE and Websockets
by zentara (Cardinal) on Jun 25, 2012 at 09:56 UTC

      Good tip, thanks. I'll look into it.

      "You have reached the Monastery. All our helpdesk monks are busy at the moment. Please press "1" to instantly donate 10 currency units for a good cause or press "2" to hang up. Or you can dial "12" to get connected directly to second level support."
Re: POE and Websockets
by Anonymous Monk on Jun 24, 2012 at 22:21 UTC
    There are also many examples of using websockets with AnyEvent, which some people find easier to understand than POE.