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:esign;
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:esign->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:oEvents();
Win32::GUI:ialog();
while(<$new_sock>) {
Win32::GUI:oEvents();
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);
}
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:esign;
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:esign->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:oEvents();
Win32::GUI:ialog();
while(<$new_sock>) {
Win32::GUI:oEvents();
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);
}