JamesNC has asked for the wisdom of the Perl Monks concerning the following question:
I have a pretty large app (WinXP) that uses IO::Socket::SSL to send XML commands to a hardware device. I built a front-end to it in Tk, but when I press the connect button, the GUI freezes until the socket is opened, and all of the reply has been recieved from the device and the socket is closed. On subsequent connects, it takes less time. I am guessing that the problem is that the socket is blocking? So, I tried using a non-blocking example out of the Liddie Mastering Tk book...but I couldn't get it to work with SSL (arrgh) so I thought I would give POE a try. It works, but I have one really petty performance issue that I was wondering if anyone knew how to overcome... that being is their any way to speed this up or at least let me move the window while it is running? using ASPerl(5.80) POE(0.25) Tk(8.024) Here is a skeleton example:
Here is blocking example to show the difference:
JamesNC
use strict; use warnings; use Tk; use POE; use POE::Component::Client::HTTP::SSL; $|++; POE::Session->create( inline_states=> { _start => \&connect, send => \&send, get_input => \&get_input, listen => \&listen, }, ); $poe_kernel->run(); sub connect { my ($kernel,$heap,$session) = @_[KERNEL,HEAP,SESSION]; my $buf; my $mw = $poe_main_window; $heap->{txt} = $mw->Scrolled('Text',-width, 50,-height, 20,-scroll +bars, 'osoe')->pack(-fill,'both',-expand, 1); $mw->Button(-text, 'Run', -command, $session->postback("send"))->p +ack; $kernel->yield("listen"); } sub send { my ($kernel,$session,$heap) = @_[KERNEL,SESSION,HEAP]; tie( *SSL, "POE::Component::Client::HTTP::SSL", "www.openssl.org", + "443") or warn "can't open socket\n"; if( \*SSL ){ $heap->{sock} = \*SSL; $heap->{sock}->print("GET http://index.htm \r\n"); $kernel->yield('listen'); } } sub get_input { my ($kernel,$heap) = @_[KERNEL,HEAP]; $kernel->yield('listen'); } sub listen { my ($kernel,$session,$heap) = @_[KERNEL,SESSION,HEAP]; if(defined $heap->{sock}){ my $buf; $heap->{sock}->blocking(0); $heap->{sock}->read($buf, 1024); $heap->{txt}->insert('end',$buf); } $kernel->yield('get_input'); }
Here is blocking example to show the difference:
Thanks in advance,use Net::SSLeay::Handle; use Tk; my $mw = tkinit; my $txt = $mw->Scrolled('Text', -width,50,-height,20, -scrollbars, 'os +oe')->pack(-fill,'both',-expand,1); $mw->Button(-text,'Run',-command, \&send)->pack; MainLoop; sub send { tie (*SSL, "Net::SSLeay::Handle", "www.openssl.org", "443") or die + "error in tie\n"; if(\*SSL){ print SSL "GET http://index.html \r\n"; } while(my $buf = <SSL>){ $txt->insert('end',$buf); } }
JamesNC
update (broquaint): added missing line of code
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Tk POE SSL Win32 help
by JamesNC (Chaplain) on Jul 29, 2003 at 13:25 UTC | |
Re: Tk POE SSL Win32 help
by paulbort (Hermit) on Jul 29, 2003 at 20:09 UTC | |
by JamesNC (Chaplain) on Jul 29, 2003 at 20:40 UTC | |
Re: Tk POE SSL Win32 help
by hiseldl (Priest) on Jul 30, 2003 at 13:14 UTC | |
by JamesNC (Chaplain) on Jul 30, 2003 at 13:27 UTC |
Back to
Seekers of Perl Wisdom