Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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



  • 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 having a coffee break in the Monastery: (3)
As of 2024-04-25 20:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found