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

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.

Replies are listed 'Best First'.
Re^7: Server with GUI
by zentara (Cardinal) on Jun 03, 2012 at 09:42 UTC
    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
      I tried Wx::Socket. I got error loading wxSOCKET_WAITALL

      Here's my Tk Version so far.

      #!/usr/local/bin/perl use Tk; use IO::Socket; use Net::Address::IP::Local; use Sys::Hostname; use Socket; use Socket; use IO::Socket::INET; my $address = Net::Address::IP::Local->public; my($ipaddr)=inet_ntoa((gethostbyname(hostname))[4]); $local = IO::Socket::INET->new( Proto => 'tcp', LocalAddr => "$ipaddr:8087", ) or die "$!"; $local->listen(); $local->autoflush(1); my $addr; #Not sure why I have this while ($addr = $local->accept() ) { print "Connection from: ", $addr->peerhost(),"\n"; print "Ready for command.\n\n"; $path = "C:/Program Files (x86)/Common Files/X10/Common"; chdir($path) or die "Cant chdir to $path $!"; #Don't know what + this does ~s/GET//g,~s/~/ /g,~s/%20/ /g,~s/%22/ /g,~s/x10command=DEVICE/ +/g, ~s/\//\ /g,~s/[?]//g ,~s/'/ /g,~s/HTTP/ /g,~s/1.1/ /g; system(AHCMD. "$_"); my $mw = new MainWindow; my $frm_name = $mw -> Frame() -> pack(); my $lab = $frm_name -> Label(-text=>"Your IP is $address Port 8087") + -> pack(); my $but = $mw -> Button(-text=>"Launch Server", -command =>\&push_butt +on) -> pack(); my $txt = $mw -> Text(-width=>40, -height=>25) -> pack(); #Needs to be + multi line. MainLoop; sub push_button { #Rather than push button, I need the client to tri +gger this @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); @weekDays = qw(Sun Mon Tue Wed Thu Fri Sat Sun); ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWee +k, $dayOfYear, $daylightSavings) = localtime(); $year = 1900 + $yearOffset; $theTime = "$hour:$minute:$second, $weekDays[$dayOfWeek] $months[$mon +th] $dayOfMonth, $year"; $txt -> insert('end', "Connection From: " ); $txt -> insert('end', $addr->peerhost() ); $txt -> insert('end', "\n" ); $txt -> insert('end', "$theTime \n" ); $txt -> insert('end',"Received: $_"); #The text that was receiv +ed print "Received: $_ \n"; print $addr $_; #print $path $_; #close $addr; chomp; #Not sure what this does print "Ready for next command....\n\n"; #Really don't need + this and don't want the black box showing . close $addr; # close client } }
        chomp; #Not sure what this does

        Dear gg4000, you are being like the Sourcerer's Apprentice. Even after I told you multiple times, not to mix select and while loops in your Wx GUI code, you do it again with Tk code. It's especially exasperating to me since I pointed you to Tk server code which you could use on MSWindows at Mastering Perl/Tk's solution to Window's fileevent quirkiness

        You just keep diving in over your head, and asking us to jump in and save you. You can google for non-GUI server-clients and learn how they work. You are just plain clueless as to how code works. You somehow think you can copy and paste code together and expect it to work. Sorry I had to say it, but it's the truth.


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