Win32::GUI Text File not getting updated

S

steve

Hi,
I'm trying to learn a few things with the Win32::GUI side of things
and sockets.
I created a very simple receiver socket script and a sender script
which work in as much that I can send different 'messages' between
them :)

Then I tried the same using a Win32::GUI setup, simple window with a
textfield where the messages should appear as I send them, but nothing
happens until I exit the window (with an Exit Button) at which point
all the messages appear in the textfield.

The applications is obviously stuck in some loop somewhere that is
preventing the update of the textfield, but I cant figure it out :-(

Here is my code for both send and receiver.....

Sender##############################################################
use IO::Socket;
my $sock = new IO::Socket::INET (
PeerAddr => 'localhost',
PeerPort => '7070',
Proto => 'tcp',
);
die "Could not create socket: $!\n" unless $sock;
print "sending 1st...";
print $sock "1,c:\\temp\\test.txt\n";
sleep(5);
print "sending 2nd...";
print $sock "3,c:\\temp\\test_2.txt\n";
sleep(5);
print "sending 3rd...";
print $sock "4";
close($sock);

Receiver##############################################################
#!/usr/local/bin/perl -w

use strict;
use IO::Socket;
use Switch;
use warnings;
use Win32::GUI;
use Win32();
use Win32::GUI::Loft::Design;

eval {
main();
};
sleep(10);

Win32::GUI::MessageBox(0, "Error: $@", "hello Demo") if($@);

sub main {
my $fileWindow = "receiver.gld"; #You created this using
The GUI Loft

my $objDesign = Win32::GUI::Loft::Design->newLoad($fileWindow) or
die("Could not open window file
($fileWindow)");

$objDesign->buildWindow() or die("Could not build window
($fileWindow)");

$Win32::GUI::Loft::window{Rx_Window}->Show();
my $sock = new IO::Socket::INET (
LocalHost => 'localhost',
LocalPort => '7070',
Proto => 'tcp',
Listen => 1,
Reuse => 1,
);
die "Could not create socket: $!\n" unless $sock;
my $new_sock = $sock->accept();
Win32::GUI::DoEvents();
Win32::GUI::Dialog();

while(<$new_sock>) {
Win32::GUI::DoEvents();
RxMsg($_);
}
close($sock);
return(1);
}

sub RxMsg {
my @actions = split(/,/);
switch ($actions[0]) {
case 1 {defined(my $win = $Win32::GUI::Loft::window{Rx_Window})
or return(1);
$win->RxTextfield->Append("action 1\r\n");
chomp($actions[1]);
$win->RxTextfield->Append("$actions[1]\r\n");
open ACTION, "< $actions[1]" or die "cant open file : $!";
while (my $line = <ACTION> ) {
$win->RxTextfield->Append("$line\r\n");
}
}
case 2 {defined(my $win =
$Win32::GUI::Loft::window{Rx_Window}) or return(1);
$win->RxTextfield->Append("action 2\r\n");
}
case 3 {defined(my $win =
$Win32::GUI::Loft::window{Rx_Window}) or return(1);
$win->RxTextfield->Append("action 3\r\n");
chomp($actions[1]);
$win->RxTextfield->Append("$actions[1]\r\n");
open ACTION, "< $actions[1]" or die "cant open file : $!";
while (my $line = <ACTION> ) {
$win->RxTextfield->Append("$line\r\n");
}
}
else {defined(my $win = $Win32::GUI::Loft::window{Rx_Window})
or return(1);
$win->RxTextfield->Append("action unknown\r\n");
}
}
return(1);
}

sub ::ExitBtn_Click { defined(my $win =
$Win32::GUI::Loft::window{Rx_Window}) or return(1);

#Just exit
return(-1);
}
 
R

Robert May

I created a very simple receiver socket script and a sender script
which work in as much that I can send different 'messages' between
them :)

Then I tried the same using a Win32::GUI setup, simple window with a
textfield where the messages should appear as I send them, but nothing
happens until I exit the window (with an Exit Button) at which point
all the messages appear in the textfield.

The applications is obviously stuck in some loop somewhere that is
preventing the update of the textfield, but I cant figure it out :-(

[snip code]
Win32::GUI::Dialog();

Try removing that line from your receiver - it won't return until you
close your window. Win32::GUI::DoEvents() is the 'non-blocking'
equivalent.

Regards,
Rob.
 
S

steve

I created a very simple receiver socket script and a sender script
which work in as much that I can send different 'messages' between
them :)
Then I tried the same using a Win32::GUI setup, simple window with a
textfield where the messages should appear as I send them, but nothing
happens until I exit the window (with an Exit Button) at which point
all the messages appear in the textfield.
The applications is obviously stuck in some loop somewhere that is
preventing the update of the textfield, but I cant figure it out :-(

[snip code]
Win32::GUI::Dialog();

Try removing that line from your receiver - it won't return until you
close your window. Win32::GUI::DoEvents() is the 'non-blocking'
equivalent.

Regards,
Rob.

Many Thanks Rob,
works an treat now

regards
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top