in reply to Re: Tk and blocking loops
in thread Tk and blocking loops
fileevent doesn't work with ActivePerl 5.6.1 or 5.8.0. I'm not sure about other versions. I'm really upset about the whole thing, too, since POE requires fileevent to work with Tk.
Anyway, here's a test case (pure Tk) that you can use to verify whether fileevent works with your OS/Perl/Tk environment. It should be portable across UNIX and Win32.
-- Rocco Caputo - troc@pobox.com - poe.perl.org
#!/usr/bin/perl -w use strict; use Tk; use Symbol qw(gensym); use IO::Socket; $ENV{HOME} = "/" unless $ENV{HOME}; print( "Listening on localhost port 31415. Telnet to it and try\n", "entering something. In an ideal world, it should echo back.\n +" ); my $acceptor = IO::Socket::INET->new ( LocalAddr => '127.0.0.1', LocalPort => 31415, Listen => 5, Reuse => 'yes', ); my $client = $acceptor->accept(); die "Could not accept a client: $!" unless defined $client; print "Client connection accepted.\n"; # Turn off buffering. select((select($client), $| = 1)[0]); # Send a welcome message. print $client "Hello!\x0d\x0a"; print "Setting callback for $client.\n"; my $main_window = Tk::MainWindow->new(); $main_window->fileevent( $client, 'readable', [ \&read_client ] ); print "Callback set.\n"; Tk::MainLoop(); exit 0; sub read_client { print "Client callback has been invoked.\n"; my $line = <$client>; exit unless defined $line; print $client $line; }
|
|---|