Net::X...:Client(3pm)

okay so this is the User Contributed Perl Documentation page for Net::X...:Client(3pm) β€” aka the XMPP Client Module β€” and it is literally your group-chat cheat sheet for talking XMPP in Perl πŸ’–βœ¨

πŸ’– NAME πŸ’–

Net::XMPP::Client β€” XMPP Client Module. short, iconic, does what it says πŸ’…

✨ SYNOPSIS ✨

Net::XMPP::Client is a module that gives a developer easy access to the Extensible Messaging and Presence Protocol (XMPP). no cap, that's the whole vibe πŸ¦‹

πŸ¦‹ DESCRIPTION πŸ¦‹

Client.pm uses Protocol.pm to give you enough high level APIs and automation of the low level APIs that writing an XMPP Client in Perl is trivial. if you want to work with the low level yourself, you can do that too β€” those functions are covered in the documentation for each module. πŸ‘‘

Net::XMPP::Client gives you functions to connect to an XMPP server, login, send and receive messages, set personal information, create a new user account, manage the roster, and disconnect. you can use all or none of the functions β€” there is no requirement, bestie 🫢

for more information on how the details for how Net::XMPP is written, please see the help for Net::XMPP itself.

for a full list of high level functions available, please see Net::XMPP::Protocol.

🌸 Basic Functions 🌸

use Net::XMPP;

$Con = Net::XMPP::Client->new();

$Con->SetCallbacks(...);

$Con->Execute(hostname=>"jabber.org",
              username=>"bob",
              password=>"XXXX",
              resource=>"Work"
             );

for the list of available functions see Net::XMPP::Protocol.

$Con->Disconnect();

πŸ‘‘ METHODS πŸ‘‘

🌸 Basic Functions 🌸

🌟 new 🌟

new(debuglevel=>0|1|2,
    debugfile=>string,
    debugtime=>0|1)

creates the Client object. πŸ’… debugfile should be set to the path for the debug log to be written. if set to "stdout" then the debug will go there. debuglevel controls the amount of debug. for more information about the valid settings for debuglevel, debugfile, and debugtime, see Net::XMPP::Debug.

πŸ”Œ Connect πŸ”Œ

Connect(hostname=>string,
        port=>integer,
        timeout=>int,
        connectiontype=>string,
        tls=>0|1,
        srv=>0|1,
        componentname=>string)

opens a connection to the server listed in the hostname (default localhost), on the port (default 5222) listed, using the connectiontype listed (default tcpip). the two connection types available are:

tcpip  standard TCP socket
http   TCP socket, but with the
       headers needed to talk
       through a web proxy

if you specify tls, then TLS will be used if it is available as a feature. ✨

if srv is specified AND Net::DNS is installed and can be loaded, then an SRV query is sent to srv.hostname and the results processed to replace the hostname and port. if the lookup fails, or Net::DNS cannot be loaded, then hostname and port are left alone as the defaults.

alternatively, you may manually specify componentname as the domain portion of the jid and leave hostname set to the actual hostname of the XMPP server. 🫢

πŸŒ€ Execute πŸŒ€

Execute(hostname=>string,
        port=>int,
        tls=>0|1,
        username=>string,
        password=>string,
        resource=>string,
        register=>0|1,
        connectiontype=>string,
        connecttimeout=>string,
        connectattempts=>int,
        connectsleep=>int,
        processtimeout=>int)

generic inner loop to handle connecting to the server, calling Process, and reconnecting if the connection is lost. there are five callbacks available that are called at various places:

  • onconnect β€” when the client has made a connection.
  • onauth β€” when the connection is made and user has been authed. essentially, this is when you can start doing things as a Client. like send presence, get your roster, etc...
  • onprocess β€” this is the most inner loop and so gets called the most. be very very careful what you put here since it can DRASTICALLY affect performance. 😭
  • ondisconnect β€” when the client disconnects from the server.
  • onexit β€” when the function gives up trying to connect and exits.

the arguments are passed straight on to the Connect function, except for connectattempts and connectsleep. connectattempts is the number of times that the Component should try to connect before giving up. -1 means try forever. the default is -1. connectsleep is the number of seconds to sleep between each connection attempt.

if you specify register=>1, then the Client will attempt to register the specified account for you, if it does not exist. πŸ’–

πŸ’€ Process πŸ’€

Process(integer)

takes the timeout period as an argument. if no timeout is listed then the function blocks until a packet is received. otherwise it waits that number of seconds and then exits so your program can continue doing useful things. NOTE: this is important for GUIs. you need to leave time to process GUI commands even if you are waiting for packets. the following are the possible return values, and what they mean:

    1   - Status ok, data received.
    0   - Status ok, no data received.
 undef - Status not ok, stop processing.

IMPORTANT: you need to check the output of every Process. if you get an undef then the connection died and you should behave accordingly. 🚨

πŸ‘‹ Disconnect πŸ‘‹

Disconnect()

closes the connection to the server. bye server, it's been real πŸ’…

πŸ¦‹ Connected πŸ¦‹

Connected()

returns 1 if the Transport is connected to the server, and 0 if not.

🌟 AUTHOR 🌟

originally authored by Ryan Eatmon.

previously maintained by Eric Hacker.

currently maintained by Darian Anthony Patrick. πŸ’–

this module is free software, you can redistribute it and/or modify it under the LGPL 2.1. periodt πŸŽ€


okay bye bestie 🫢 β€” this page is perl v5.42.0, dated 2016-01-12, from Net::X...:Client(3pm). mwah πŸ’‹

πŸ“¦ where this page comes from