Mike Chambers

code = joy

Connecting Anonymously to an XMPP Group Chat using XIFF

with 2 comments

I posted some code the other day that showed how to use the XIFF AS3 Library to connect to an XMPP server and join a group chat room.

Below is an slightly modified example that shows how to login anonymously, and connect to a room.

import org.jivesoftware.xiff.conference.Room;
import org.jivesoftware.xiff.core.JID;
import org.jivesoftware.xiff.core.XMPPSocketConnection;
import org.jivesoftware.xiff.events.LoginEvent;
import org.jivesoftware.xiff.events.RoomEvent;
import org.jivesoftware.xiff.events.XIFFErrorEvent;

private var connection:XMPPSocketConnection;

private function onCreationComplete():void
{
	connection = new XMPPSocketConnection();
	connection.useAnonymousLogin = true;
	connection.server = "mesh.local";
	connection.port = 5222;

	connection.addEventListener(LoginEvent.LOGIN, onLogin);
    connection.addEventListener(XIFFErrorEvent.XIFF_ERROR, onError);	

	connection.connect("standard");
}

private function onLogin(e:LoginEvent):void
{
	var room:Room = new Room(connection);
	room.roomJID = new JID("test@conference.mesh.local");
	room.nickname = "frank";
	room.addEventListener(RoomEvent.ROOM_JOIN, onRoomJoin);
	room.join();
}

private function onRoomJoin(e:RoomEvent):void
{
	Room(e.target).sendMessage("im here");
}

private function onError(e:XIFFErrorEvent):void
{
	trace(e.errorCode);
}

The two differences are that you set:

connection.useAnonymousLogin = true;

and dont send a username and password. Once you join the room, you can then set your nick like so:

room.nickname = "frank";

I have set up a test chat room on my server if you want to play around with the code.

Written by mikechambers

August 18th, 2008 at 10:54 am

Posted in General

2 Responses to 'Connecting Anonymously to an XMPP Group Chat using XIFF'

Subscribe to comments with RSS or TrackBack to 'Connecting Anonymously to an XMPP Group Chat using XIFF'.

  1. Glad to see you figured out the room nickname stuff.

    Tom Carden

    18 Aug 08 at 1:33 pm

  2. Does it something possible that Adobe does some work to become a sponsor of the XMPP Standards foundation as others here : http://www.xmpp.org/ (menu on the left).

    Tek

    8 Sep 08 at 7:46 am

Leave a Reply