#!/usr/local/bin/perl ###################################################################### # This should be an example of how to share the mainloop between # an http server through HTTP::Daemon and the Gtk main loop. # # Dov Grobgeld # 2001-02-25 ###################################################################### use Gtk; use HTTP::Daemon; use HTTP::Status; Gtk->init; my $port = 3333; $window = Gtk::Widget->new("Gtk::Window", -type => "-toplevel", -title => "GtkHTTP", -delete_event => sub { exit } ); my $vbox = Gtk::VBox->new(0, 1); $window->add($vbox); $label = Gtk::Widget->new("Gtk::Label", -label => "Listening to port $port"); $label->set_usize(400,20); $vbox->pack_start($label, 0,1,0); $button = Gtk::Widget->new("Gtk::Button", -label => "Clear", -clicked => sub { $label->set_text(""); } ); $vbox->pack_start($button, 0,1,0); $window->show_all(); # Create a web server my $d = new HTTP::Daemon LocalAddr=>'localhost', LocalPort => $port; $window->Gtk::Gdk::input_add(fileno($d), 1, [sub { my $d = shift; my $c = $d->accept; my $r = $c->get_request; if ($r->method eq 'GET') { $label->set_text($r->url->path); $c->send_basic_header(); $c->send_crlf(); print $c "

Thank you!

\n"; print $c "You asked \"" . $r->url->path . "\".
\n"; } $c->close; undef($c); }, $d]); main Gtk;