hxmpp

HXMPP is a crossplatform library for creating XMPP based jabber 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/

Hxmpp website: http://hxmpp.disktree.net/
Hxmpp source code: https://github.com/tong/hxmpp/

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

haxelib install hxmpp

Example usage:

The following example demonstrates how to:

  • Etablish a connection with a XMPP server
  • Initiate the XMPP/XML stream
  • Authenticate
  • Publish your presence
  • Listen for incoming messages and respond to with a message

class XMPPClient {
    
    static function onMessage( m : xmpp.Message ) {
        stream.sendMessage( m.from, "Hello!" ); // send response message
    }
    
    static function main() {
        var jid = new jabber.JID( 'romeo@example.com' );
        var cnx = new jabber.SocketConnection( jid.domain );
        var stream = new jabber.client.Stream( cnx );
        stream.onOpen = function(){
            trace( 'XMPP stream opened, proceed with authentication ....' );
            var auth = new jabber.client.Authentication( stream, [
                new jabber.sasl.MD5Mechanism()
            ] );
            auth.onSuccess = function() {
                trace( 'Succesfully authenticated as ['+jid+']' );
                new jabber.MessageListener( stream, onMessage ); // listen for incoming messages
                stream.sendPresence(); // send initial presence
            }
            auth.onFail = function( info : String ) {
                trace( 'Failed to authenticate ['+info+']' );
            }
            auth.start( 'mypassword', 'resource' );
        }
        stream.onClose = function(?e){
            trace( 'XMPP stream closed ['+e+']' );
        }
        stream.open( jid );
    }
    
}

To compile the client application for the nekoVM run the following command on your terminal:

haxe -main XMPPClient -neko client.n -lib hxmpp -D JABBER_DEBUG -D XMPP_DEBUG

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

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

version #13868, modified 2012-04-28 22:05:53 by tong