New to POE, so please be gentle.
Using Tk and POE to write a client. Have read that there are some issues
with Tk, POE and ActiveStates Perl on Win32; however, I think my problems
are more basic. I am using the TkClient example from the Cookbook as the
basis of my Tk interface.
I have been able to successfully connect to a server, display status
messages in the Tk windows and receive input from the server. I cannot send
info to the server. Would like to tie the 'Request Update' button to the
'send' event. How do I do this?
vitals:
POE = v0.27
OS=Windows 2000
ActiveStates Perl = v 5.8.0 Build 806
--- client.pl -----
#!/perl/bin/perl
use warnings;
use strict;
use Tk;
use POE;
use POE::Filter::Stream;
use POE::Component::Client::TCP;
local $| = 1;
my $svr = "localhost"; # Server's ip address
my $port = "32080"; # Server's port which app is running on.
my $status = "Starting point...";
# Create the session that will drive the user interface.
POE::Session->create
( inline_states =>
{ _start => \&ui_start,
ct_start => sub {
$_[HEAP]->{server}=POE::Component::Client::TCP->new
( Alais => 'web',
RemoteAddress => $svr,
RemotePort => $port,
Connected => \&handle_connect,
ConnectError => \&handle_connect_error,
Disconnected => \&handle_disconnect,
ServerInput => \&handle_server_input,
ServerError => \&handle_server_error,
ServerFlushed => \&handle_server_flush,
send => \&handle_send,
); $status = "Connected"; },
cv_send => \&handle_send, # This doesnt work, but
when I push the "request update" button I come here.
}
);
# Run the program until it is exited.
$poe_kernel->run();
sub ui_start {
my ( $kernel, $session, $heap ) = @_[ KERNEL, SESSION, HEAP ];
$poe_main_window->Label( -text => "Counter" )->pack;
$heap->{counter_widget} =
$poe_main_window->Label( -textvariable => \$status )->pack;
$poe_main_window->Button
( -text => "Connect",
-command => $session->postback("ct_start")
)->pack;
$poe_main_window->Button
( -text => "Request Update",
-command => $session->postback("cv_send") #
subst 'send' for 'cv_send' doesnt work
)->pack;
$poe_main_window->Button
( -text => "Disconnect",
-command => $session->postback("Disconnect")
)->pack;
$status="Press Connect Button";
}
sub handle_start {
my @args = @_[ARG0..$#_];
}
sub handle_connect {
$status = "2Connected";
}
sub handle_send {
my ($kernel, $heap,$input_record) = @_[KERNEL, HEAP, ARG0];
chomp $input_record;
print "Server send $input_record\n";
$_[HEAP]->{server}->put("$input_record\n") ; # <<<<<< This doesnt work
}
sub handle_connect_error {
my ( $kernel, $heap, $syscall_name, $error_number, $error_string) =
@_[KERNEL, HEAP,ARG0, ARG1, ARG2];
$status = "I had problems.\n$syscall_name\n
$error_number\n$error_string";
}
sub handle_disconnect {
my ($kernel, $heap ) = @_[ KERNEL, HEAP ];
#$kernel->yield("shutdown");
$status = "Disconnect me.";
}
sub handle_server_input {
my ($kernel, $heap,$input_record) = @_[KERNEL, HEAP, ARG0];
chomp $input_record;
$status = "Server input:$input_record";
#print "Server input >$input_record<\n";
#$_[HEAP]->{server}->put("1") if ($input_record ne "Update requested");
}
sub handle_server_error {
my ($syscall_name, $error_number, $error_string) = @_[ARG0, ARG1, ARG2];
$status = "I had an error:\n$syscall_name\n
$error_number\n$error_string";
}
sub handle_server_flush {
# no special parameters
$status= "Time to flush\n";
}
Thank you,
Tom