haXe library for building XMPP/jabber clients and components.

Install/Source.

haxelib install hxmpp
Latest source code can be cloned from a git repository or browsed online.
git clone git://github.com/tong/hxmpp.git

Documentation.

API documentation
UML diagrams

Usage.

Compiler flags.

A echo client.

Below is the haXe source code of a simple jabber client which responds with a dumb "Hello" to every chat message.

	
import jabber.client.Stream;
import jabber.client.SASLAuth;

class EchoBot {
	
	static var HOST = "disktree";
	static var IP = "127.0.0.1";
	static var JID = "username@"+HOST;
	static var PASSWORD = "mypassword";
	static var RESOURCE = "HXMPP";
	
	static var stream : Stream;
	
	static function main() {
		
		#if (flash||js)
		if( haxe.Firebug.detect() )
			haxe.Firebug.redirectTraces(); 
		#end
		
		// crossplatform stuff, using the 'best' connection available for the target
		#if ( js && !nodejs && !JABBER_SOCKETBRIDGE )
		var cnx = new jabber.BOSHConnection( HOST, IP+"/jabber" );
		#else
		var cnx = new jabber.SocketConnection( IP, 5222 );
		#end
		#if JABBER_SOCKETBRIDGE trace( "Using flash socketbridge to connect to server" ); #end
		
		var jid = new jabber.JID( JID );
		stream = new Stream( cnx );
		stream.onClose = function(?e) {
			if( e == null ) trace( "XMPP stream closed." );
			else trace( "An XMPP stream error occured: "+e );
		}
		stream.onOpen = function() {
			var auth = new SASLAuth( stream, [
				cast new jabber.sasl.MD5Mechanism(),
				cast new jabber.sasl.PlainMechanism
			] );
			auth.onSuccess = function() {
				new jabber.MessageListener( stream, handleMessage );
				stream.sendPresence();
				trace( "Logged in as "+JID );
			}
			auth.authenticate( PASSWORD, RESOURCE );
		}
		stream.open( jid );
	}
	
	// handle incoming messages
	static function handleMessage( m : xmpp.Message ) {
		if( xmpp.Delayed.fromPacket( m ) != null )
			return; // avoid processing of offline sent messages
		var jid = new jabber.JID( m.from ); // parsing the 'from' into a jabber-id
		trace( "Recieved message from "+jid.bare+" at resource: "+jid.resource );
		stream.sendPacket( new xmpp.Message( m.from, "Hello darling aka "+jid.node ) );
	}
	
}
	
	
	haxe -neko echo.n -main EchoBot -cp ../hxmpp -D XMPP_DEBUG -D JABBER_DEBUG
	haxe -swf9 echo.swf -main EchoBot -cp ../hxmpp -D XMPP_DEBUG -D JABBER_DEBUG
	haxe -js echo.js -main EchoBot -cp ../hxmpp -D XMPP_DEBUG -D JABBER_DEBUG -D JABBER_SOCKETBRIDGE
	haxe -php . --php-front echo.php -main EchoBot -cp ../hxmpp -D XMPP_DEBUG -D JABBER_DEBUG
	

The XMPP_DEBUG flag is set to print the XMPP transfer for debugging.
The JABBER_DEBUG flag prints verbose debug messages and allows you to use local (invalid) domain names.
For the JS target the JABBER_SOCKETBRIDGE flag is required to use a (invisible) flash movie as bridge for the socket connection.

Using BOSH with apache.

BOSH essentially provides a "drop-in" alternative to a long-lived, bidirectional TCP connection using a request-response mechansim over HTTP.
To use it you have to connect your client to the BOSH adress of your jabber server. Your webserver doesn’t know about your jabber server .. you have to setup a proxy to forward requests:
		http://localhost/http/ to http://localhost:7070/http-bind/
	
Activate the mod_proxy apache module if required.
		sudo ln /etc/apache2/mods-available/proxy.load /etc/apache2/mods-enabled
	
Add following line to proxy.load to load the module.
		LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
	
Add the proxy directive to the host settings in your http.conf.
		ProxyRequests Off
		ProxyPass /http http://localhost:7070/http-bind/
		ProxyPassReverse /http http://localhost:7070/http-bind/
	
Restart apache.
		sudo /etc/init.d/apache2 restart
	
Refer to the documentation of the HTTP connection manager of your jabber server.

Flash usage.

If you are are flash or actionscript3 developer who don't want to use haXe you can download a SWC.
The SWC isn't updated frequently therfore better download the project source files and build the SWC yourself ( use hxmpp/libs.hxml ).

XEPs implemented.

XEPs marked with an asterisk are in a experimental state.
Checkout the latest source code for updates not listed here.

Related projects.

HXMPP.console XMPP transfer debug console for browser targets
HXMPP.test unit tests

Contribute.

Patches are always welcome, the process is simple:

git clone git://83.64.208.21/hxmpp.git
cd hxmpp
# edit file
gid add [file]
git commit -m "Description of what your patch does"
git format-patch HEAD^

License.

HXMPP is licensed under GNU Lesser General Public License v3.

Contact.

xmpp://tong@jabber.spektral.at