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();
}
}
}