in reply to Re^3: Server with GUI
in thread Server with GUI

Well it's been a long week of trial and error.

Had things happen with Tk, had things happen with Wx.

I'm back to the start. Wx.

The window opens after the server gets a connection. The Window has to open and display the IP First.

Then display the text from the client. And display the next set of text from the client.

And send the commands to the computer. I'm still stuck with "What to do instead of While"

#!/usr/bin/perl package main; use IO::Socket; use Sys::Hostname; use Socket; use 5.008; #use strict; use Wx; use wxPerl::Constructors; use base 'Wx::App'; use Wx qw(wxTE_MULTILINE wxVERTICAL wxID_DEFAULT); #use warnings; my($ipaddr)=inet_ntoa((gethostbyname(hostname))[4]); $| = 1; my $app = Demo::App->new; $app->MainLoop; package Demo::App; #use strict; #use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; #use strict; #use warnings; use Wx qw(:everything); use base 'Wx::Frame'; sub new { #print "Ready for next command.\n\n"; my ($class) = @_; my $self = $class->SUPER::new( undef, -1, "X10 Voice Commander", wxDefaultPosition, wxDefaultSize, ); $self->{text} = Wx::TextCtrl->new($self, -1, "", [-1,-1], [300, 300], +wxTE_MULTILINE); $self->{text}->AppendText("Use Your IP $ipaddr:8087 on your devi +ce.\n"); #$self->{text}->AppendText("Connection from: ", $addr->peerhost(), +"\n"); #sub serv { $local = IO::Socket::INET->new( Proto => 'tcp', # protocol LocalAddr => "$ipaddr:8087", ) or die "$!"; my $addr; $local->listen(); $local->autoflush(1); while ($addr = $local->accept() ) { print "Connection from: ", $addr->peerhost(),"\n"; while (<$addr>) { $path = "C:/Program Files (x86)/Common Files/X10/Common"; chdir($path) or die "Cant chdir to $path $!"; ~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://; system(AHCMD. "$_"); print "Received: $_"; print $addr $_; print $path $_; close $addr; chomp; return $self; } } }

And a test client.....
use IO::Socket; use Sys::Hostname; my($ipaddr)=inet_ntoa((gethostbyname(hostname))[4]); $remote = IO::Socket::INET->new( Proto => 'tcp', # protocol PeerAddr=> "$ipaddr:8087", PeerPort=> "8087", # port of server Reuse => 1, ) or die "$!"; print "Connected to ", $remote->peerhost, # Info message " on port: ", $remote->peerport, "\n"; $remote->autoflush(1); # Send immediately while (<>) { # Get input from STDIN print $remote " "; print $remote "sendplc "; print $remote $_; # Send to Server #last if m/^end/gi; # If 'end' then exit loop my $line = <$remote>; # Receive echo from server if ($line ne $_) { # If not the same as input #print "Error in sending output\n"; # error exit; # Terminate } print "End of client\n"; # End of client close $remote; # Close socket exit }
Run the server first. Type anything into the client. Commands are if you have X10 installed "A1 On"

Replies are listed 'Best First'.
Re^5: Server with GUI
by zentara (Cardinal) on Jun 02, 2012 at 10:28 UTC
    Have you seen Gtk2 server and client GUI's with root messaging? :-) It should work on Windows. Wx generally uses Gtk libs as a basis, so if you have Wx installed you can probably install Gtk2. See Installing Gtk2 using PPM on Windows and Install GTK2 for example.

    But back to Wx:

    I don't have Wx running, but looking at your server code, I see you did not get the previous point I was making about GUI eventloop code, and using sleep, system, while loops, select loops, or anything which interferes with the eventloop. Your code , as written, will just hang in the while loop, making the Wx eventloop freeze up. I don't even have to run it to see that.

    You must use Wx::Socket to run sockets in Wx. Otherwise, you need to put all your while loops into a separate thread, and at your level of programming experience, I doubt you are up to that hassle. Go back and rewrite your code using the example code in Wx::Socket


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
      I tried many different ways to install Gtk2. It just won't install. I'll keep trying though.

      I'll keep trying different things with Tk and Wx

      I was also trying to figure out how to reform the server without the "while". I need the part after the While to complete the next step.
      while ($addr = $local->accept() ) { print "Connection from: ", $addr->peerhost(),"\n";
      I don't know what I can slip in instead of While.
        From Wx::Socket you use $client->GetPeer

        ########## # SERVER # ########## my $sock = Wx::SocketServer->new('localhost',5050,wxSOCKET_WAITALL); EVT_SOCKET_CONNECTION($parent , $sock , \&onConnect ) ; if ( !$sock->Ok ) { print "ERROR\n" ;} sub onConnect { my ( $sock , $this , $evt ) = @_ ; my $client = $sock->Accept(0) ; my ($local_host,$local_port) = $client->GetLocal ; my ($peer_host,$peer_port) = $client->GetPeer ; $client->Write("This is a data test!\n") ;
        You might want to post another new SOPW node titled "need help with Wx::Socket" to get the attention of Wx users, as my experience with it, and desire to study it, is nill.

        I'm not really a human, but I play one on earth.
        Old Perl Programmer Haiku ................... flash japh