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

I've been working on this server for a few days. What day is it anyway? : )

The problem is that the window opens only after the connection is made.

The window has to open first. It will then show the IP, Date/Time. Then get updated every time the text comes from the client.

Everything else is working. The filtered text gets filtered out, the command is sent to the system.

I don't think I need most of the "USE" commands, but I can try to filter them out later.

I also know that the "While" is a problem. But I need the part after the while to run the rest of the code.

#!/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 { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, "X10 Voice Commander", wxDefaultPosition, wxDefaultSize, );$local = IO::Socket::INET->new( Proto => 'tcp', # protocol LocalAddr => "$ipaddr:8087", ) or die "$!"; my $addr; $local->listen(); $local->autoflush(1); while ($addr = $local->accept() ) { 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; $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: "); $self->{text}->AppendText($addr->peerhost()); $self->{text}->AppendText("\n"); $self->{text}->AppendText("Received: $_"); } return $self; #This has something to do with it? Return where??? } }
Here is a test Client. But it will only run once.

Would like it to continue sending what is typed.
use IO::Socket; use Sys::Hostname; my($ipaddr)=inet_ntoa((gethostbyname(hostname))[4]); $remote = IO::Socket::INET->new( Proto => 'tcp', PeerAddr=> "$ipaddr:8087", Reuse => 1, ) or die "$!"; print "Connected to ", $remote->peerhost, " on port: ", $remote->peerport, "\n"; $remote->autoflush(1); # Send immediately while (<>) { print $remote " "; print $remote "sendplc "; print $remote $_; # Send to Server }#Want to keep the client running.

Replies are listed 'Best First'.
Re: Wx Server reform
by ww (Archbishop) on Jun 03, 2012 at 12:24 UTC

    Not a full answer to your problems... but a start: At line 7 (and numerous other spots), you comment out "use strict;" and/or "use warnings;"

    That's a mistake.

    strict will tell you when and where (or pretty close) you've made typos (such as using two different spellings for a single $var) and the like. Keep "use strict" (and "use warnings") in ALL your code until you know precisely why you should omit it.

    OTOH, you're probably right about deleting "use 5.008" unless you are using a very old version of Perl. Current is 5.16 (or 5.14 if your vendor hasn't caught up).

    Now, some WAGs, as I find your problem statement and code confusing (or maybe because it's pre-caffeine of a Sunday am):

    Re your while problem: perhaps using an equality test rather than an assignment would be worth considering?

    And, "return where?" -- looks to me like an exit from the package to return to your main.

    Thank goodness, the kettle's whistling.

      Hi,

      Thank you for the quick reply!

      I'm new to Perl. Last time I remember making Windows programs was 25 years ago.
      With VB, and it was easy as Windows 3.0. Now it's so complicated.

      The Strict and Warnings were holding me up from going further. I do plan on adding them back.

      Re your while problem: perhaps using an equality test rather than an assignment would be worth considering?
      I don't know what to put there instead of while.

      And, "return where?" -- looks to me like an exit from the package to return to your main.
      I don't want to exit...I think? I need the server to stay online and listen for new commands, then update the text.
      I also don't want the text highlighted. The recorded text should remain in the box un-editable.

        1. strict and warnings: Put them back NOW. Let Perl help you see (some of) your (other) mistakes.
        2. while: The suggestion was that you pay attention to the difference between =, assignment and ==, equality test.
        3. return: Since you didn't understand the above and you don't seem know where you're sending a return value, you probably should heed -- assiduously -- the suggestion "study a good book on fundamentals."