use IO::Socket; use IO::Select; use Tk; use strict; my $mw = MainWindow->new; my $text = $mw->Text->pack(); my $button = $mw->Button(-text=>"quit",-command=>sub{exit;})->pack; my $sock = IO::Socket::INET->new( Listen => 5, Reuse => 1, LocalPort => 7076, Proto => 'tcp', ) or die "Couldn't open socket: $!"; my $sel = IO::Select->new; $sel->add($sock); $mw->repeat(50 => \&read_sock); MainLoop; sub read_sock { my(@ready) = $sel->can_read(0); return if $#ready == -1; my $line; my $new_sock = $sock->accept(); $line = <$new_sock>; $text->insert('end',"$line\n"); }