hxmpp

HXMPP is a crossplatform library for creating XMPP based clients and components.

The Extensible Messaging and Presence Protocol (XMPP) is an open technology for real-time communication, which powers a wide range of applications including instant messaging, presence, multi-party chat, voice and video calls, collaboration, lightweight middleware, content syndication, and generalized routing of XML data.

The XMPP protocols are free, open, public, and easily understandable.
To learn more, see http://xmpp.org/

In order to use HXMPP, you need to install the library using haxelib (or clone git repository).

haxelib install hxmpp

The following example demonstrates how to:

  • Etablish a connection with a XMPP server
  • Initiate the XMPP/XML stream
  • Authenticate client account
  • Publish initial 'available' presence
  • Listen for incoming messages and automatically respond with 'Hello!'

class XMPPClient {

    static function main() {

        var jid = new jabber.JID( 'user@example.com' );
        var cnx = new jabber.SocketConnection( jid.domain );
        var stream = new jabber.client.Stream( cnx );
        stream.onOpen = function(){
            
            trace( 'XMPP stream opened, authenticating client ....' );
            
            var auth = new jabber.client.Authentication( stream, [new jabber.sasl.MD5Mechanism()] );
            auth.onSuccess = function() {

                trace( 'Authenticated as : ${jid.toString()}' );

                stream.sendPresence(); // send initial presence

                new jabber.MessageListener( stream, function(m){ // listen for incoming messages
                    stream.sendMessage( m.from, "Hello!" );
                });
            }
            auth.onFail = function(e) {
                trace( 'Failed to authenticate : $e' );
            }
            auth.start( 'mypassword', 'hxmpp-example-client' );
        }
        stream.onClose = function(?e){
            trace( 'XMPP stream closed : $e' );
        }
        stream.open( jid );
    }

}

Run the following command to build the application for the neko platform:

$ haxe -main XMPPClient -neko client.n -lib hxmpp -D jabber_debug -D xmpp_debug

The jabber_debug flag prints additional debug information and allows to use invalid formatted jabber-ids (jid) like user@test (instead of user@example.com).

The xmpp_debug flag prints the XML stream you exchange with the server.

version #19427, modified 2013-06-07 19:37:25 by tong