http://www.perlmonks.org?node_id=1056740

simonz has asked for the wisdom of the Perl Monks concerning the following question:

Hi
I have written a per tk script, which first create a mainwindow and then starts a server program and client program. But the problem is if I shift the 'MainLoop' statement in the end of the script after the initiation of server and client , then the gui is not appearing although the server is getting started.
On the other hand if I put the 'MainLoop' before the server and client initiation statements then the gui is starting , but the execution control only goes to the server-client statement only after closing the gui. All I want is that the gui should start and simultaneously the server and client should also start in sequence.
For the server and client code you can refer to my code pasted in How to introduce threading in socket communication. Similar code is getting executed in Server::initServer() and Client::initClient() routines respectively.

## my script ##

use Tk; use Server; use Client; my $mw = MainWindow->new(); #MainLoop; #gui appears but the control goes below only after clos +ing the gui,hence server does not start when the gui is open print "after mainloop \n"; my $server = Server->new(parentWnd=>$mw); $server->initServer(); my $client = Client->new(parentWnd=>$mw); $client->initClient(); MainLoop; #does not bring up the gui but the server starts.