Time out SSL request?

Discussion in 'Perl' started by Michael Capone, Dec 19, 2003.

  1. Hi folks,

    I'm using perl (actually, mod_perl environment on RH 8.0) to connect
    to an external SSL server. I feed it an XML request and get a
    response back. The problem is, the server is flaky, and I'd like to
    be able to timeout / break if I haven't gotten a response in X
    seconds. (Note that the server may connect, but simply not send a
    response, i.e., it's too busy.)

    I don't really understand filehandles and setting timeouts in unix /
    perl. The code below was lifted from the Net::SSLeay readme and
    worked, and I never questioned it further.

    Could someone show me how to modify the code below to add my timeout?
    Note that I'm also completely open to other methods of connecting to
    an SSL server; the Net::SSLeay method seemed to be the quickest to
    implement, and I have no idea if there's a better way out there.

    Thanks!

    Michael

    #!/usr/local/bin/perl -w

    use strict;
    use Net::SSLeay::Handle qw/shutdown/;

    my ($request, $response) ;

    local *F;
    my $FH = *F;

    $request = <<ENDXML;
    <?xml version="1.0"?>
    <Request>
    <UserId>user1</UserId>
    <Password>pass1</Password>
    </Request>
    ENDXML

    my ($host, $port) = ("www.some.server", 443);
    tie(*SSL, "Net::SSLeay::Handle", $host, $port);

    print SSL "POST /xmlapps/blah HTTP/1.0\n";
    print SSL "Content-type: application/x-www-form-urlencoded\n";
    print SSL "Content-length: " . length($request) . "\n\n";
    print SSL $request;

    shutdown(\*SSL, 1);

    $response .= $_ while (<SSL>);
    close SSL;
    print $response;
    Michael Capone, Dec 19, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve
    Replies:
    0
    Views:
    5,327
    Steve
    Jul 1, 2003
  2. Brian Birtle
    Replies:
    2
    Views:
    2,013
    John Saunders
    Oct 16, 2003
  3. flamesrock
    Replies:
    8
    Views:
    449
    Hendrik van Rooyen
    Nov 24, 2006
  4. Gelonida N
    Replies:
    0
    Views:
    525
    Gelonida N
    Feb 27, 2012
  5. Michael Capone

    Time out SSL request?

    Michael Capone, Dec 23, 2003, in forum: Perl Misc
    Replies:
    2
    Views:
    103
    Michael Capone
    Dec 31, 2003
Loading...

Share This Page