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

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

Replies are listed 'Best First'.
Re^6: Server with GUI
by gg4000 (Novice) on Jun 02, 2012 at 22:38 UTC
    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
        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 } }