haxelib install hxmpp
git clone git://github.com/tong/hxmpp.git
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.
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-enabledAdd following line to proxy.load to load the module.
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.soAdd 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 restartRefer to the documentation of the HTTP connection manager of your jabber server.
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^