IO::Socket and LWP::UserAgent

tim tim.hunt at its.monash.edu.au
Thu Nov 21 00:16:58 CST 2002


Hello.

I'm trying to connect to a service provider using two methods:

HTTPS:// GET via LWP::UserAgent;
TCP/IP stream via IO::Socket::SSL;

In each case I'm sending information to be SMSed to mobile phones.

My script instantiates an object and then calls the specific ->send()
method; in each case the object is reused. The HTTPS method is about
three times faster than the socket method. The socket seems to put one
message per second, whilst the supplier has suggested that 20 per second
is achievable.

Am I missing something intrinsic about IO::Socket::SSL (and IO::Socket
in general), or shoudl I be talking to the provider to get their system
tuned? They use Win NT as their server, and that's about all I know :)

Thanks in advance,

Tim.

----------

[SCRIPT]
my $sms = new Monash::SMS_Stunnel($account, $pass);
my $ssl_mobile_number = '0419xxxxxxxxx';
my $message = 'TEXT for test purposes';
my $str;
map {
    $response = $sms->send_socket_SSL($ssl_mobile_number, $message);
    if ($response) {
        $str = "Message $_ sent from process $$";
    } else {
        $str = "Message $_ failed from process $$";
    }
    carp $str;
} (1..200);

[MODULE]

sub new
{
   use IO::Socket::SSL;
   my $remote_ssl = IO::Socket::SSL->new(
               Proto=> 'tcp',
               PeerAddr => 'xx.xx.xx.xx',
               PeerPort => 'xxx',
           )
             or die "cannot connect to [SSL] server";

    my ($clazz, $account_name, $passwd) = @_;

    my $self = {
        _account_name   => $account_name,
        _passwd     => $passwd,
        _remote_ssl => $remote_ssl,
    };

    bless $self, $clazz;
    return $self;
}

sub send_socket_SSL($)
{
    my ($self,$mobile_number,$message) = @_;

    # These three should form part of the object invocation:
    my $sender = 'xxxxxx';
    my $sender_address = 'xxxxxxxxxxxxxx';
    my $recipient = 'xxxxxxxxxxxxx';
    my $remote = $self->{_remote_ssl};
    # Okay, let's send it!
    print $remote qq{\r\r}.$self->{_account_name}.qq{\r1\r1\r}.
        qq{$sender\r}.
        qq{$sender_address\r}.
        qq{$recipient\r}.
        qq{$mobile_number}.
        qq{\rGSM}.
        qq{\r0\r0\r0\r}.$self->{_passwd}.qq{\r}.
        qq{$message};

    # Send result
    # Accepted Result code = 0x06 Description = Lodge OK
    # Rejected Result code = 0x15 Description = Lodge Error

    my $strbuff = '';
    $remote->read($strbuff,10,0);
    # Next line for debug purposes only:
#   print "\nstrbuff was ($strbuff)\n";
    if ($strbuff =~ /Lodge OK/) {
        return 1;
    } else {
        return 0;
    }
}

__END__



More information about the Melbourne-pm mailing list