Home > Archive > PERL POE > February 2007 > POE and XUL
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Rutger Vos 2007-02-23, 7:24 pm |
| Dear POE programmers,
I am attempting to write a POE program that does two things:
1. construct and manage a POE::Component::XUL application;
2. follow a growing log file.
The idea is that the log file follower sends new lines in the log to the XUL
application, to be displayed in a TextWindow XUL widget. As far as the XUL
app is concerned - I got that figured out: it shows up in the browser
window, and the buttons (etc.) do what I mean for them to do. Likewise, the
log follower does what it's supposed to do, at least in so far as writing
changes to the log to STDOUT. What doesn't seem to work is for those same
changes to show up in the textwindow.
Now, although I am a reasonable programmer, I must admit to a bit of voodoo
programming in regards to POE - I'm reading the wiki, and trying to get my
head around things, but it's a lot to take in. I assume things going wrong
in my efforts have got something to do with the XUL app and the log follower
doing their thing in their own space, but the reference to the textwindow
that I pushed onto the HEAP when constructing the XUL app has the same
memory address (refaddr) as the one that the log follower pulls off the heap
when executing the log following callbacks, and still it's not working.
I hope you don't mind me posting some code, to clarify:
########################################
###############
# snipped preambles...
POE::Session->create(
'inline_states' => {
'_start' => sub {
my ( $kernel, $heap, $session ) = @_[KERNEL, HEAP, SESSION];
# build XUL app
POE::Component::XUL->spawn( {
'port' => $PORT, # from @ARGV
'root' => $ROOT, # from @ARGV
'apps' => {
'Regman' => sub { # Regman = Registry Manager
# widget construction happens here
XUL::Node::Application::Regman->VERBOSE( $VERBOSE );
my $regman = XUL::Node::Application::Regman->_new;
# push logwindow onto heap
$heap->{'_logwindow'} = $regman->{'_logwindow'};
# return main window, this works, shows in firefox
return $regman->_main;
}
},
} );
# the following is a blatant c&p from the wiki
$_[HEAP]->{'wheel'} = POE::Wheel::FollowTail->new(
'Filename' => $LOGFILE, # from @ARGV
'InputEvent' => 'got_line',
'ErrorEvent' => 'got_error',
'S Back' => 1024,
);
$_[HEAP]->{'first'} = 0;
},
'got_line' => sub {
# this is the same logwindow as when the xul app was constructed
my $logwindow = $_[HEAP]->{'_logwindow'};
if ( $_[HEAP]->{'first'}++ && defined $logwindow ) {
# these messages show up when the log changes
print "MESSAGE FROM LOGWATCHER: " . $_[ARG0] . "\n";
# attempt to send msg to xul widget
$logwindow->value( $_[ARG0] );
# sure enough, the widget is modified, but not in firefox?
# i.e. ->value() has changed, but the actual text widget
# shows nothing?
print "LISTENING TO LOGWINDOW: " . $logwindow->value() .
"\n";
}
elsif ( $_[HEAP]->{'first'}++ && ! defined $logwindow ) {
print "MESSAGE FROM LOGWATCHER: " . $_[ARG0] . "\n";
}
},
'got_error' => sub {
my $logwindow = $_[HEAP]->{'_logwindow'};
if ( $_[HEAP]->{'first'}++ && defined $logwindow ) {
my $current = $logwindow->value;
$logwindow->value( $current . "\n" . $_[ARG0] );
print "MESSAGE FROM LOGWATCHER: " . $_[ARG0] . "\n";
}
elsif ( $_[HEAP]->{'first'}++ && ! defined $logwindow ) {
print "MESSAGE FROM LOGWATCHER: " . $_[ARG0] . "\n";
}
},
},
);
########################################
###############
Any hints as to what might be going on?
Thanks,
Rutger
| |
| David Davis 2007-02-23, 7:24 pm |
| Whoops, forgot to cc the list.
David
---------- Forwarded message ----------
From: David Davis <david.davis@gmail.com>
Date: Feb 23, 2007 11:00 AM
Subject: Re: POE and XUL
To: Rutger Vos <rvosa@sfu.ca>
The problem with the xul poco is that you can't send data back to the
browser unless an action warrants it. You click a button, it hits the
server and the data is sent back. I hit this same wall when I wrote poco
xul.
What you really need is cometd. http://cometd.com/ I'm the lead dev on
the project and I will have the perl / poe server working soon. Perhaps
this w end. I want to integrate cometd with XUL too, so I'll let you know
when I have something. Until then, feel free to join the mailing list for
cometd, located on the site.
Cheers!
David
On 2/23/07, Rutger Vos <rvosa@sfu.ca> wrote:
>
> Dear POE programmers,
>
> I am attempting to write a POE program that does two things:
>
> 1. construct and manage a POE::Component::XUL application;
>
> 2. follow a growing log file.
>
> The idea is that the log file follower sends new lines in the log to the
> XUL
> application, to be displayed in a TextWindow XUL widget. As far as the XUL
> app is concerned - I got that figured out: it shows up in the browser
> window, and the buttons (etc.) do what I mean for them to do. Likewise,
> the
> log follower does what it's supposed to do, at least in so far as writing
> changes to the log to STDOUT. What doesn't seem to work is for those same
> changes to show up in the textwindow.
>
> Now, although I am a reasonable programmer, I must admit to a bit of
> voodoo
> programming in regards to POE - I'm reading the wiki, and trying to get my
> head around things, but it's a lot to take in. I assume things going wrong
> in my efforts have got something to do with the XUL app and the log
> follower
> doing their thing in their own space, but the reference to the textwindow
> that I pushed onto the HEAP when constructing the XUL app has the same
> memory address (refaddr) as the one that the log follower pulls off the
> heap
> when executing the log following callbacks, and still it's not working.
>
> I hope you don't mind me posting some code, to clarify:
>
> ########################################
###############
> # snipped preambles...
>
> POE::Session->create(
> 'inline_states' => {
> '_start' => sub {
> my ( $kernel, $heap, $session ) = @_[KERNEL, HEAP, SESSION];
>
> # build XUL app
> POE::Component::XUL->spawn( {
> 'port' => $PORT, # from @ARGV
> 'root' => $ROOT, # from @ARGV
> 'apps' => {
> 'Regman' => sub { # Regman = Registry Manager
>
> # widget construction happens here
> XUL::Node::Application::Regman->VERBOSE( $VERBOSE
> );
> my $regman = XUL::Node::Application::Regman->_new;
>
>
> # push logwindow onto heap
> $heap->{'_logwindow'} = $regman->{'_logwindow'};
>
> # return main window, this works, shows in firefox
>
> return $regman->_main;
> }
> },
> } );
>
> # the following is a blatant c&p from the wiki
> $_[HEAP]->{'wheel'} = POE::Wheel::FollowTail->new(
> 'Filename' => $LOGFILE, # from @ARGV
> 'InputEvent' => 'got_line',
> 'ErrorEvent' => 'got_error',
> 'S Back' => 1024,
> );
> $_[HEAP]->{'first'} = 0;
> },
> 'got_line' => sub {
>
> # this is the same logwindow as when the xul app was
> constructed
> my $logwindow = $_[HEAP]->{'_logwindow'};
> if ( $_[HEAP]->{'first'}++ && defined $logwindow ) {
>
> # these messages show up when the log changes
> print "MESSAGE FROM LOGWATCHER: " . $_[ARG0] . "\n";
>
> # attempt to send msg to xul widget
> $logwindow->value( $_[ARG0] );
>
> # sure enough, the widget is modified, but not in firefox?
> # i.e. ->value() has changed, but the actual text widget
> # shows nothing?
> print "LISTENING TO LOGWINDOW: " . $logwindow->value() .
> "\n";
> }
> elsif ( $_[HEAP]->{'first'}++ && ! defined $logwindow ) {
> print "MESSAGE FROM LOGWATCHER: " . $_[ARG0] . "\n";
> }
> },
> 'got_error' => sub {
> my $logwindow = $_[HEAP]->{'_logwindow'};
> if ( $_[HEAP]->{'first'}++ && defined $logwindow ) {
> my $current = $logwindow->value;
> $logwindow->value( $current . "\n" . $_[ARG0] );
> print "MESSAGE FROM LOGWATCHER: " . $_[ARG0] . "\n";
> }
> elsif ( $_[HEAP]->{'first'}++ && ! defined $logwindow ) {
> print "MESSAGE FROM LOGWATCHER: " . $_[ARG0] . "\n";
> }
> },
> },
> );
>
> ########################################
###############
>
> Any hints as to what might be going on?
>
> Thanks,
>
> Rutger
>
| |
| Tavin Cole 2007-02-23, 7:24 pm |
| have you figured out a way to make the connection truly interactive, in
the sense that the client can send a message at any time while receiving
the multipart server push, without opening a second connection?
i ran into lots of problems trying that, where i couldn't get firefox to
send a streaming request body, and i couldn't get apache to give the
request stream to the CGI/PHP/ModPerl instead of buffering it until the
whole content-length is read.
no doubt you can solve the problem server-side with POE, but what about
the client-side?
-tavin
David Davis wrote:
> Whoops, forgot to cc the list.
>
> David
>
> ---------- Forwarded message ----------
> From: David Davis <david.davis@gmail.com>
> Date: Feb 23, 2007 11:00 AM
> Subject: Re: POE and XUL
> To: Rutger Vos <rvosa@sfu.ca>
>
> The problem with the xul poco is that you can't send data back to the
> browser unless an action warrants it. You click a button, it hits the
> server and the data is sent back. I hit this same wall when I wrote poco
> xul.
>
> What you really need is cometd. http://cometd.com/ I'm the lead dev on
> the project and I will have the perl / poe server working soon. Perhaps
> this w end. I want to integrate cometd with XUL too, so I'll let you
> know
> when I have something. Until then, feel free to join the mailing list for
> cometd, located on the site.
>
> Cheers!
> David
>
> On 2/23/07, Rutger Vos <rvosa@sfu.ca> wrote:
>
| |
| Rutger Vos 2007-02-24, 8:22 am |
| Hi David,
thanks for the reply! Can you think of a way to fake what I'm trying to
achieve? The least satisfying solution (but still some sort of an option)
would be a "refresh" button, but is there some other way to periodically
fire events (in a non-blocking sort of way) from within XUL to update the
log window? Any hints greatly appreciated!
Rutger
On Fri, 23 Feb 2007 11:02:00 -0800 david.davis@gmail.com wrote:[color=darkred]
> Whoops, forgot to cc the list.
>
> David
>
> ---------- Forwarded message ----------
> From: David Davis <david.davis@gmail.com>
> Date: Feb 23, 2007 11:00 AM
> Subject: Re: POE and XUL
> To: Rutger Vos <rvosa@sfu.ca>
>
> The problem with the xul poco is that you can't send data back to the
> browser unless an action warrants it. You click a button, it hits the
> server and the data is sent back. I hit this same wall when I wrote poco
> xul.
>
> What you really need is cometd. http://cometd.com/ I'm the lead dev on
> the project and I will have the perl / poe server working soon. Perhaps
> this w end. I want to integrate cometd with XUL too, so I'll let
> you know
> when I have something. Until then, feel free to join the mailing list for
> cometd, located on the site.
>
> Cheers!
> David
>
> On 2/23/07, Rutger Vos <rvosa@sfu.ca> wrote:
> the XUL
writing[color=darkred]
same[color=darkred]
> get my
> wrong
textwindow[color=darkred]
$VERBOSE[color=darkred]
> XUL::Node::Application::Regman->_new;
> firefox
> firefox?
| |
| Tavin Cole 2007-02-24, 7:16 pm |
| yeah, that's why the "Web 2.0" makes me laugh.. didn't we have
bidirectional protocols 30 years ago?
anyway, i'd argue that HTTP *can* be used as a bidirectional protocol.
if the client sends a chunked request body with no content length, and
the server sends a chunked response body with no content length, you
have achieved bidirectionality. HTTP effectively becomes a tunnel for a
bidirectional protocol based on XML or whatever you care to use.
the only major hitch is whether you can get software like firefox (or
dear gods, IE) to play along. we can assume we can control the server
side and fix apache or just use POE etc.
-tavin
Philip Gwyn wrote:[color=darkred]
> Breifly, cometd is an AJAX implement.
>
> AJAX works by using HTTP requests "in the background," that is not a page load.
> HTTP is a client-driven/initiated request/response protocol. That is, clien
> opens the connection, sends a request, server responds. Repeat
> if using keep-alive.
>
> Which is to say, it is impossible to convert an HTTP connection into a general
> by-directional protocol.
>
> Cometd works around this by having the server queuing up requests, and the
> client polling for them every X seconds.
>
> There are also, I believe, more advanced/complex techniques. But I don't
> remember the details.
>
> Regarding apache, back in the day nph-cgi was used for server-push stuff (like
> animations, pre-animated gif/flash days)
>
> -Philip
>
> On 23-Feb-2007 Tavin Cole wrote:
|
|
|
|
|