in reply to endless loops for server and tk

this is perfectly possible with Tcl/Tk GUI with Tcl::Tk CPAN module.

Tcl/Tk has fileevent which resolves the problem.

I have written bluetooth COM-keyboard driver this way, which works both for linux and windows. The essential part is

use Tcl::Tk; my $int = new Tcl::Tk; # ..... $int->fileevent($fhbt, readable => \&process_keyboard); # .... $int->MainLoop;
This is what you asked - file operations awake callbacks when in GUI MainLoop.