Dear monks

I am playing with the Chat module Net::XMPP and so far it is working great. I am able to send and receive instant messages. What I am trying to do now is to use the CONNECT function in order to create an account on a server from the client if the account the client is trying to connect to does not exist (provided the service provider allow account creation from client). Here I fail. Please see the code below:

Updated: to reconnect to server, just in case, as suggested by roboticus (however same error with the Execute operation)

#!/usr/bin/perl use strict; use warnings; use Net::XMPP; use Mozilla::CA qw( ); my ($recipient, $message) = @ARGV; if(!($recipient) || !($message)) { print "Usage: $0 \n"; exit; } my $hostname = ''; my $sender = ''; my $password = '; my $connection = new Net::XMPP::Client(); print "Connecting to server. "; my $status = $connection->Connect( hostname => $hostname, connectiontype => 'tcpip', tls => 1, port => 5222, ssl_ca_path => Mozilla::CA::SSL_ca_file(), ); die("XMPP connection failed $!") if ! defined($status); print "Done!\n"; my @result = $connection->AuthSend( hostname => $hostname, username => $sender, password => $password); #die("XMPP authentication failed") if $result[0] ne 'ok'; if ($result[0] ne 'ok'){ print "XMPP authentication failed. Creating a new account\n"; print "Connecting again to server. "; my $status = $connection->Connect( hostname => $hostname, connectiontype => 'tcpip', register=>1, tls => 1, port => 5222, ssl_ca_path => Mozilla::CA::SSL_ca_file(), ); die("XMPP connection failed $!") if ! defined($status); print "Done!\n"; print "Trying to register new account. "; my @result = $connection->Execute( hostname=>$hostname, port=>5222, tls=>1, username=>$sender, password=>$password, #resource=>"new", register=>1, connectiontype=>'tcpip', #connecttimeout=>string, connectattempts=>2, connectsleep=>2, processtimeout=>3, ); } die("Creation account failed") if $result[0] ne 'ok'; my @messages = ('first message', 'second', 'third'); foreach (@messages){ die("XMPP message failed") if ($connection->MessageSend(to => $recipie +nt, body => $_) != 0); sleep 3; } print "Message sent!\n";

The error I get is:

There was an error in the last call to Process that you did not check +for and handle. You should always check the output of the Process call. If i +t was undef then there was a fatal error that you need to check. There is a +n error in your program

In reply to Net::XMPP registering account from client by Takamoto

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.