in reply to Tk fileevent with win32 sockets

My experience has been that the types of filehandles that "work properly" under Windows is a null set.

In a recently developed program I ended up using a 'master' program to handle the GUI and its events, and a 'slave' program to handle all the socket-based IO (LWP::Useragent et. al. in this case). The two programs used Tie::Win32MemMap (and thus Win32::MemMap) to pass data back and forth.

The tkcomics example from O'Reilly's Mastering Perl/Tk shows a good example of this, and a good method of writing a multi-platform program that selects the use of filevents or Tie::Win32MemMap in a BEGIN block.

Replies are listed 'Best First'.
Re^2: Tk fileevent with win32 sockets
by massimo (Initiate) on Aug 17, 2004 at 07:59 UTC
    In the end I found that a "reasonable" tradeoff in term of portability is
    the following solution based on "select" and "repeat".
    use IO::Select; my ($server, $server_port, $timeout, $maxlisten); $maxlisten=5; $timeout=50; if (@ARGV<1) { $server_port=9876; } else { $server_port=shift; } my $top = MainWindow->new(); $server = IO::Socket::INET->new(LocalPort => $server_port, Type => SOCK_STREAM, Reuse => 1, Listen => $maxlisten ); $top->repeat($timeout,[\&recedata, $server]); MainLoop(); sub recedata { my $server=shift; my $s=IO::Select->new($server); my @ready=$s->can_read(0); if ($ready[0] == $server) { warn "in recedata\n"; my $client=$server->accept(); my $data=<$client>; print "$data\n"; my $t2 = $top->Scrolled('Text'); $t2->pack(-expand => 1, -fill => 'both'); tie (*TEXT2, 'Tk::Text',$t2); print TEXT2 "$data\n"; close ($client); } }
    Thanks to all people who replied to my question!