Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: tk mainwindow not appearing

by keszler (Priest)
on Oct 03, 2013 at 10:56 UTC ( [id://1056745]=note: print w/replies, xml ) Need Help??


in reply to tk mainwindow not appearing

You say
Similar code (to 1056724) is getting executed in Server::initServer() and Client::initClient() routines respectively.
And
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.
Without a listing of Server.pm and Client.pm my only guess is that $server->initServer(); or $client->initClient(); is not returning. Probably the former as you don't mention the client getting started.

Replies are listed 'Best First'.
Re^2: tk mainwindow not appearing
by simonz (Sexton) on Oct 03, 2013 at 11:05 UTC

    Hi keszler
    # The Server.pm ##

    package Server; use IO::Socket; use IO::Select; use strict; sub new { my $class = shift; my %args = @_; my $self = { parentWnd => $args{parentWnd} }; bless $self, $class; return $self; } sub initServer { my $self = shift; my $server = IO::Socket::INET::->new(Proto => 'tcp', LocalPort => 55555, Listen => 1, Reuse => 1 ) or die "Server can't start: $!" +; my $readable_handles = new IO::Select(); $readable_handles->add($server); my $buf; while (1) { # select() blocks until a socket is ready to be read or written my ($new_readable) = IO::Select->select($readable_handles, undef, undef, 0); # If it comes here, there is at least one handle # to read from or write to. For the moment, worry only about # the read side. foreach my $sock (@$new_readable) { if ($sock == $server) { my $new_sock = $sock->accept(); # Add it to the list, and go back to select because the # new socket may not be readable yet. print "Adding it \n"; $readable_handles->add($new_sock); } #- server part else { #print STDERR "Reading...\n"; print "Reading...$sock \n"; # It is an ordinary client socket, ready for reading. $buf = <$sock>; if ($buf) { #- print the buffer print "Read $buf\n"; # .... Do stuff with $buf } else { # Client closed socket. We do the same here, and remove # it from the readable_handles list print "removing it \n"; $readable_handles->remove($sock); close($sock); } } } } } 1;
    ## the Client.pm ###
    package Client; use IO::Socket; sub new { my $class = shift; my %args = @_; my $self = { parentWnd => $args{parentWnd} }; bless $self, $class; return $self; } sub initClient { my $self = shift; my $client = IO::Socket::INET::->new( Proto => 'tcp', PeerAddr => 'localhost', PeerPort => 55555 ) or die "Client can't connect: $!"; my @msgs = 1 .. 10; for (@msgs) { print $client "$_\n"; sleep 1; } } 1;
      The initServer subroutine's while loop has no exit; your main program never gets past the $server->initServer(); line. You'll need to make Server and Client fork a child process to run thosethat endless loop, or look into IPC::Run, Thread::Queue, or the many links above in the AnonyMonk reply.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1056745]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-20 01:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found