Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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:
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:
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); } }
Thanks in advance,
JamesNC

update (broquaint): added missing line of code


In reply to Tk POE SSL Win32 help by JamesNC

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-03-29 13:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found