Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Comment on

( #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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (9)
    As of 2014-07-13 19:20 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (251 votes), past polls