Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Net::XMPP registering account from client

by Takamoto (Monk)
on Dec 07, 2019 at 11:27 UTC ( [id://11109799]=perlquestion: print w/replies, xml ) Need Help??

Takamoto has asked for the wisdom of the Perl Monks concerning the following question:

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

Replies are listed 'Best First'.
Re: Net::XMPP registering account from client
by roboticus (Chancellor) on Dec 07, 2019 at 13:16 UTC

    Takamoto:

    I've never used Net::XMPP before, so I may be out in left field, but I'd guess by the error message that when your auth failed, the server disconnected the connection. (That sort of error message often implies that an internal value in the object is undef, such as the connection handle.) Because of that, it might simply be that you need to do another Connect before trying to register.

    I'm sorry in advance if I'm off-base.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11109799]
Approved by hippo
Front-paged by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-24 21:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found