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

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

Hello I'm close. The problem is that the GUI will not open until the server gets a connection. The GUI should open first showing the IP of the computer, ready to receive commands, and show the command. Please help! Here's the code.....

#!/usr/bin/perl<br> package main;<br> use IO::Socket;<br> use Sys::Hostname;<br> use Socket;<br> use 5.008;<br> #use strict;<br> #use warnings;<br> my($ipaddr)=inet_ntoa((gethostbyname(hostname))[4]);<br> $| = 1;<br> my $app = Demo::App->new;<br> # create the WxApplication<br> #$self->SetSize($text->GetSizeWH);<br> $app->MainLoop;<br> package Demo::App;<br> #use strict;<br> #use warnings;<br> use base 'Wx::App';<br> sub OnInit {<br> my $frame = Demo::App::Frame->new;<br> $frame->Show(1);<br> }<br> package Demo::App::Frame;<br> #use strict;<br> #use warnings;<br> use Wx qw(:everything);<br> use base 'Wx::Frame';<br> sub new {<br> my ($class) = @_;<br> my $self = $class->SUPER::new(<br> undef, -1,<br> 'Demo::App',<br> wxDefaultPosition, wxDefaultSize,<br> );<br> my $text = Wx::StaticText->new( $self, -1, "For X10 Voice Commande +r Use IP $ipaddr\n Port 8086\n");<br> #sub serv {<br> $local = IO::Socket::INET->new(<br> Proto => 'tcp', # protocol<br> LocalAddr => "$ipaddr:8086", <br> ) or die "$!";<br> my $addr; <br> $local->listen(); <br> $local->autoflush(1); <br> while ($addr = $local->accept() ) { <br> print "Connection from: ", $addr->peerhost(),"\n"; <br> while (<$addr>) <br> { <br> $path = "C:/Program Files (x86)/Common Files/X10/Common";<br> chdir($path) or die "Cant chdir to $path $!";<br> ~s/GET//,~s/~/ /g,~s/%20/ /g,~s/%22/ /g,~s/x10command=DEVICE/ +/,~s/\//\ /g,~s/[?]//g ,~s/'/ /g,~s/HTTP/ /,~s/1.1/ /g,~s/sh://;<br> system(AHCMD. "$_");<br> print "Received: $_"; <br> print $addr $_; <br> print $path $_; <br> close $addr;<br> chomp;<br> return $self; <br> } <br> }<br> }<br>