Please Help with XIFF an Gtalk

Hi everyone, I’m tryng to create a simple chat (i just wan’t to chat with one other buddy). I only get those errors:

  • Service Unavailable

  • rror: Error #2048: Violazione della sicurezza sandbox: file:///Users/francescopensabene/Desktop/demo_chat_xmpp/bin-debug/demo.swf non può caricare dati da talk.google.com:5222.

Here’s my code.

I hope someone could help or just tell me where to find help on-line

Thanks

/=====================================/

package
{
import com.hurlant.crypto.tls.TLSConfig;

import flash.display.*;
import flash.events.*;
import flash.system.Security;
import flash.text.*;
import flash.ui.Keyboard;
import flash.utils.Timer;

import org.igniterealtime.xiff.core.*;
import org.igniterealtime.xiff.data.*;
import org.igniterealtime.xiff.events.*;


import org.igniterealtime.xiff.events.*;

import com.hurlant.crypto.tls.TLSEngine;
import com.hurlant.crypto.tls.TLSConfig;

[SWF(backgroundColor = '0x5B5B5B', frameRate = '33', width = '600', height = '400')]

/**
 * @see [http://paazio.nanbudo.fi/tutorials/flash/xiff-chat-part-1](http://paazio.nanbudo.fi/tutorials/flash/xiff-chat-part-1)
 */
public class demo extends Sprite
{
    private const SERVER:String = "talk.google.com";
    private const PORT:Number = 5222;
    private const USERNAME:String = "fpensabene@gmail.com";
    private const PASSWORD:String = "daniela2804";
   
    //private const RESOURCE_NAME:String = "flashPlayer";
    private const RESOURCE_NAME:String = "xiff";
   
    private const CHECK_POLICY:Boolean = true;
   
   
    private var _connection:XMPPTLSConnection;
   
   
    private var _keepAlive:Timer;
    private var _outputField:TextField;
    private var _inputField:TextField;
   
    // inidirizzo della controparte con cui chattiamo
   
    //private var _chattingWith:EscapedJID = new EscapedJID("tonttu@" + SERVER);
    private var _chattingWith:EscapedJID = new EscapedJID("travelcyborg@europelowcost.com");
   
    public function demo()
    {   
       
        trace("eseguo demo");
        stage.align = StageAlign.TOP_LEFT;
        stage.scaleMode = StageScaleMode.NO_SCALE;
       
        loaderInfo.addEventListener(Event.INIT, onInit);
    }
   
    private function onInit(event:Event):void
    {   
       
        trace("eseguo onInit()");
        if (CHECK_POLICY)
        {
            Security.loadPolicyFile("xmlsocket://" + SERVER + ":5229");
            //Security.loadPolicyFile("xmlsocket://" + SERVER + "crossdomain.xml");
        }
       
        createElements();
        initChat();
    }
   
    private function createElements():void
    {
        var format:TextFormat = new TextFormat("Verdana", 12, 0x121212);
       
        _outputField = new TextField();
        _outputField.background = true;
        _outputField.backgroundColor = 0xCCCCCC;
        _outputField.mouseWheelEnabled = true;
        _outputField.multiline = true;
        _outputField.width = stage.stageWidth - 4;
        _outputField.height = stage.stageHeight - 54;
        _outputField.x = 2;
        _outputField.y = 2;
        addChild(_outputField);
       
        _inputField = new TextField();
        _inputField.background = true;
        _inputField.backgroundColor = 0xEEEEEE;
        _inputField.type = "input";
        _inputField.width = stage.stageWidth - 4;
        _inputField.height = 48;
        _inputField.x = 2;
        _inputField.y = stage.stageHeight - 50;
        _inputField.maxChars = 40;
        _inputField.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
        addChild(_inputField);
    }
   
    private function addMessage(from:EscapedJID, msg:String):void
    {
        var date:Date = new Date();
        _outputField.appendText("[" + date.getHours() + ":" + date.getMinutes() + " | " + from.node + "] " + msg + "\n");
    }
   
    private function onKeyUp(event:KeyboardEvent):void
    {
        switch(event.keyCode)
        {
            case Keyboard.ENTER :
                messageSend();
                break;
        }
    }
   
    private function messageSend():void
    {
        var txt:String = _inputField.text;
        //var msg:Message = new Message(_chattingWith, null, txt, null, Message.CHAT_TYPE);
        var msg:Message = new Message(_chattingWith, null, txt, null, Message.TYPE_CHAT);
        if (_connection.isLoggedIn())
        {
            _connection.send(msg);
            _inputField.text = "";
            addMessage(_connection.jid.escaped, txt);
        }
    }
   
    private function initChat():void
    {
        //_connection = new XMPPSocketConnection();
        _connection = new XMPPTLSConnection();

_connection.port = PORT;

        _connection.username = USERNAME;
        _connection.password = PASSWORD;
        _connection.domain = "gmail.com";
        _connection.useAnonymousLogin = false;
        _connection.resource = RESOURCE_NAME;
        _connection.server = SERVER;
       
       
       
        var config:TLSConfig = new TLSConfig( TLSEngine.CLIENT );
        config.ignoreCommonNameMismatch = true;
        _connection.config = config;

//_connection.connect(“flash”);
_connection.connect(XMPPConnection.STREAM_TYPE_FLASH);

        _connection.addEventListener(DisconnectionEvent.DISCONNECT, onDisconnect);
        _connection.addEventListener(XIFFErrorEvent.XIFF_ERROR, onXiffError);
        _connection.addEventListener(LoginEvent.LOGIN, onLogin);
        _connection.addEventListener(MessageEvent.MESSAGE, onMessage);
       
       
       
        _keepAlive = new Timer(2 * 60 * 1000);
        _keepAlive.addEventListener(TimerEvent.TIMER, onKeepAliveLoop);
    }
   
    private function onDisconnect(event:DisconnectionEvent):void
    {
        trace("onDisconnect. " + event.toString());
    }
   
    private function onXiffError(event:XIFFErrorEvent):void
    {
        trace("onXiffError. " + event.toString());
        trace("onXiffError.errorMessage: " + event.errorMessage);
    }
   
    private function onLogin(event:LoginEvent):void
    {
        trace("onLogin. " + event.toString());
        _keepAlive.start();
       
        // [http://www.ietf.org/rfc/rfc3921.txt](http://www.ietf.org/rfc/rfc3921.txt)
        var presence:Presence = new Presence(null, _connection.jid.escaped, null, null, null, 1);
        _connection.send(presence);
    }
   
    private function onMessage(event:MessageEvent):void
    {
        trace("onMessage. " + event.toString());
        addMessage(event.data.from, event.data.body);
    }
   
    private function onKeepAliveLoop(event:TimerEvent):void
    {
        _connection.sendKeepAlive();
    }
}

}

Hey Francesco,

I haven’t looked over all of your code, but your credentials do work with XIFF (just plugged them into XIFFGUI and connected perfectly), so there’s probably just something minor wrong.

You should check XIFFGUI out, which is in the examples of the repository now and compare your code.

PS, You should probably change your password now - since its included in the code above.

Hi Mark,

Thank you for the password hint (me stupid… ;-)) but I’m going Crazy…

I tried in XIFFGUI but nothing i put username, password (new one) and for server i use gtalk.google.com

but nothing i get auth error…

I realy need to make it work for monday can you help me please…

Thanks

Francesco

Should be talk.google.com for the server not gtalk.google.com.

Does that fix it for you?

Thanks, I’ve tryed with talk.google.com but I still get 401 error … Do you think it is a firewall issue??

and please Mark can you look at my code ? Do you think it is right?? I have searched over internet

for xiff+google talk but I didn’t found anything usefull - I’m using plain as3.

I use XMPPTLSConnection()

do I have to set some authorization ???

Thankyou sorry but I’m in a hurrry … and here in Italy it is 22pm

bye

Francesco

The problem is that you are duplicating the domain.

Currently your username is set to fpensabene@gmail.com and your domain is set to gmail.com.

The jid is formed from the above two plus the resource like this:

username + “@” + domain + “/” + resource

So your jid is reading like this:

fpensabene@gmail.com@gmail.com/xiff

If a domain is provided in the username, you should split it at the “@” sign and provide the username as the first part and the domain as the second.

Mark,

Thanks for your help you where very Kind but it is not sufficient…

I tryed XIFFGUI using “talk.google.com” as server and then “fpensabene” or fpensabene@" or fpensabene@gmail.com" and relative password but nothing I always get 401 error not auth…

In my application (with flash cs4) i did the same changes but nothing my disconnect handler is always the first to run…

I tought i could find someone to read my code and help but I understand that maybe HERE this is not the way…

thanks

Francesco

just an update i have tryed…

http://yourpalmark.com/2009/02/23/xiff-gui-as3-xmpp-demo/

and

http://paazio.wippiespace.com/xiff-gui-v2.1/

i have google talk installed and it works but nothing to do with XIFF GUI … and with what I’m trying to develop…

Please do not post in multiple threads.

I have actually taken your code as you posted and made the couple of tweaks I mentioned above and gotten it to work successfully.

There are always variables and I will try to list them out to make sure you are using everything correctly:

  1. Make sure you are using the latest XIFF code from the SVN trunk here:

https://svn.igniterealtime.org/svn/repos/xiff/trunk

  1. At the bottom of this reply is the code tweaked to work (just copy and use it). You have since changed your password so make sure you change it in the code as well.

  2. If you want to test with XIFFGUI, neither of the above will work (they have not been updated to work with TLS). You have to use the one in the svn link I posted, as I mentioned above.

CODE:

package
{
import com.hurlant.crypto.tls.TLSConfig;
import com.hurlant.crypto.tls.TLSEngine; import flash.display.*;
import flash.events.*;
import flash.system.Security;
import flash.text.*;
import flash.ui.Keyboard;
import flash.utils.Timer; import org.igniterealtime.xiff.core.*;
import org.igniterealtime.xiff.data.*;
import org.igniterealtime.xiff.events.*; [SWF(backgroundColor = '0x5B5B5B', frameRate = '33', width = '600', height = '400')] /**
* @see http://paazio.nanbudo.fi/tutorials/flash/xiff-chat-part-1
*/
public class demo extends Sprite
{
private const SERVER:String = "talk.google.com";
private const PORT:Number = 5222;
private const USERNAME:String = "fpensabene";
private const PASSWORD:String = "daniela2804"; //private const RESOURCE_NAME:String = "flashPlayer";
private const RESOURCE_NAME:String = "xiff"; private const CHECK_POLICY:Boolean = true; private var _connection:XMPPTLSConnection; private var _keepAlive:Timer;
private var _outputField:TextField;
private var _inputField:TextField; // inidirizzo della controparte con cui chattiamo //private var _chattingWith:EscapedJID = new EscapedJID("tonttu@" + SERVER);
private var _chattingWith:EscapedJID = new EscapedJID("travelcyborg@europelowcost.com"); public function demo()
{    trace("eseguo demo");
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE; loaderInfo.addEventListener(Event.INIT, onInit);
} private function onInit(event:Event):void
{    trace("eseguo onInit()");
if (CHECK_POLICY)
{
Security.loadPolicyFile("xmlsocket://" + SERVER + ":5229");
//Security.loadPolicyFile("xmlsocket://" + SERVER + "crossdomain.xml");
} createElements();
initChat();
} private function createElements():void
{
var format:TextFormat = new TextFormat("Verdana", 12, 0x121212); _outputField = new TextField();
_outputField.background = true;
_outputField.backgroundColor = 0xCCCCCC;
_outputField.mouseWheelEnabled = true;
_outputField.multiline = true;
_outputField.width = stage.stageWidth - 4;
_outputField.height = stage.stageHeight - 54;
_outputField.x = 2;
_outputField.y = 2;
addChild(_outputField); _inputField = new TextField();
_inputField.background = true;
_inputField.backgroundColor = 0xEEEEEE;
_inputField.type = "input";
_inputField.width = stage.stageWidth - 4;
_inputField.height = 48;
_inputField.x = 2;
_inputField.y = stage.stageHeight - 50;
_inputField.maxChars = 40;
_inputField.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
addChild(_inputField);
} private function addMessage(from:EscapedJID, msg:String):void
{
var date:Date = new Date();
_outputField.appendText("[" + date.getHours() + ":" + date.getMinutes() + " | " + from.node + "] " + msg + "\n");
} private function onKeyUp(event:KeyboardEvent):void
{
switch(event.keyCode)
{
case Keyboard.ENTER :
messageSend();
break;
}
} private function messageSend():void
{
var txt:String = _inputField.text;
//var msg:Message = new Message(_chattingWith, null, txt, null, Message.CHAT_TYPE);
var msg:Message = new Message(_chattingWith, null, txt, null, Message.TYPE_CHAT);
if (_connection.isLoggedIn())
{
_connection.send(msg);
_inputField.text = "";
addMessage(_connection.jid.escaped, txt);
}
} private function initChat():void
{
//_connection = new XMPPSocketConnection();
_connection = new XMPPTLSConnection(); _connection.port = PORT; _connection.username = USERNAME;
_connection.password = PASSWORD;
_connection.domain = "gmail.com";
_connection.useAnonymousLogin = false;
_connection.resource = RESOURCE_NAME;
_connection.server = SERVER; var config:TLSConfig = new TLSConfig( TLSEngine.CLIENT );
config.ignoreCommonNameMismatch = true;
_connection.config = config; //_connection.connect("flash");
_connection.connect(); _connection.addEventListener(OutgoingDataEvent.OUTGOING_DATA, onOutgoingData);
_connection.addEventListener(IncomingDataEvent.INCOMING_DATA, onIncomingData);
_connection.addEventListener(DisconnectionEvent.DISCONNECT, onDisconnect);
_connection.addEventListener(DisconnectionEvent.DISCONNECT, onDisconnect);
_connection.addEventListener(XIFFErrorEvent.XIFF_ERROR, onXiffError);
_connection.addEventListener(LoginEvent.LOGIN, onLogin);
_connection.addEventListener(MessageEvent.MESSAGE, onMessage); _keepAlive = new Timer(2 * 60 * 1000);
_keepAlive.addEventListener(TimerEvent.TIMER, onKeepAliveLoop);
} private function onOutgoingData( event:OutgoingDataEvent ):void
{
trace( event.data.toString() );
} private function onIncomingData( event:IncomingDataEvent ):void
{
trace( event.data.toString() );
} private function onDisconnect(event:DisconnectionEvent):void
{
trace("onDisconnect. " + event.toString());
} private function onXiffError(event:XIFFErrorEvent):void
{
trace("onXiffError. " + event.toString());
trace("onXiffError.errorMessage: " + event.errorMessage);
} private function onLogin(event:LoginEvent):void
{
trace("onLogin. " + event.toString());
_keepAlive.start(); // http://www.ietf.org/rfc/rfc3921.txt
var presence:Presence = new Presence(null, _connection.jid.escaped, null, null, null, 1);
_connection.send(presence);
} private function onMessage(event:MessageEvent):void
{
trace("onMessage. " + event.toString());
addMessage(event.data.from, event.data.body);
} private function onKeepAliveLoop(event:TimerEvent):void
{
_connection.sendKeepAlive();
}
}
}

Hi, nothing to do I have still some problems:

1 - I used flash builder to download from svn, I wanted to try XIFFGUI but when i create a new rpoject for it It throws an error because id doesn’t find XIFF.swc in the bin folder (and in fact there isn’t …)

2 - I tryed in flash but I get : (i didn’t copyed everything …)

onXiffError.errorMessage: Service Unavailable

there was a security error of type: securityError

onXiffError.errorMessage: Not Authorized

3 - I thin another issue is :

Security.loadPolicyFile(“xmlsocket://” + SERVER + “:” + PORT);

is this right?? I lloked into XIFFGUI and i saw you did like this…

but from the svn i don’t receive the xiif.swc and i don’t think that the one in the download area is the last (or right one).

please keep helping me at the end I will make a resume for everyone I think it will be very usefull for everyone right over there.

Francesco

I created a document to help people get started with XIFF.

Check it out, I think it will help you out:

http://community.igniterealtime.org/docs/DOC-2101

Mark you are very Kind and every time you say something I learn more…

BUT i did as in your doc… downloaded the xiff.swc used with the code above

and nothing I still get : [XIFFErrorEvent type=“error” bubbles=false cancelable=false eventPhase=2]

Not Authorized

I used another google account but nothing…

my app isa on-line at: http://www.aktivo.it/chat/Main.html

YOU MANAGED TO CONNECT SO WHY I DON’T THIS IS VERY STRANGE…

I’m going Crazy!!!

[XIFFErrorEvent type=“error” bubbles=false cancelable=false eventPhase=2]

Not Authorized

But it should work for you in the XIFF GUI V 3.0.1 example. Can you get your credentials to work there?

Username: user@gmail.com

Password: *****

Login server: talk.google.com

Server port: 5222

Hit connect and it should connect you.

When this works for you, you should be able to determine what is wrong with your code.

Hi Mark,

I did it but nothing to do i alway s get 401 error not authorized

Ihave it on-line at :

http://www.aktivo.it/chat/bin-debug/XIFFGUI.html

please try your self i did exactely what you sayd in the DOC…

thanks

Francesco

Hmm very interesting. My credentials aren’t working either.

Does it work locally for you when you compile XIFFGUI?

I’ll be honest, I haven’t actually pushed a Google Talk version of XIFFGUI live to test, just local.

It seems like Google might not have a policy file located on their xmlsocket.

I apologize for the runaround on this. Had no clue you were only testing live.

It definitely does work locally.

I’ll dig some more into if Google has a policy file anywhere else.

I got Facebook to add a policy file, so if Google doesn’t have one, I’ll see if we can get them to add it.