Authenticating handshake and launch of main loop
Once we’ve set up the handlers, we’re ready to make the authenticating
handshake. This is simply a call to the auth()
method:
$c->auth('secret');
It takes either one or three arguments, depending on
whether the authentication is for a client or a component.
Jabber::Connection decides which authentication context
is required by looking at the specified (or default) namespace in the
connection constructor call. As we specified the namespace
jabber:component:accept, the auth()
method is expecting a single argument, the secret
specified in the <secret/> tag of the
component instance definition. The auth() method performs the
message digest function and sends the
<handshake/> element.
It’s now appropriate for us to “launch” the component, with the
start() method:
$c->start;
This is the equivalent of the
MainLoop() method in Perl’s Tk library and
is a method from which there’s no exit. Calling start()
causes the connection object to perform an endless loop, which internally
calls a process() method on a regular basis,
receiving, examining, and dispatching elements received on the XML stream.
It also starts and maintains the heartbeat, to which
the register_beat() method is related.
Note
If you wish to have more granular control over your script, you can use the process() function directly, just as
you would with the Net::Jabber and
Jabberpy libraries. Be aware, however, that a
heartbeat is maintained only in the context of the
start() ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access