Test performance in Java

Leave a comment

Here is the good website for me to make a performance test in Java
Click here to visit the site.

Advertisements

XMPP client in Flex with ActionScript 3

Leave a comment

I would like to share some knowledge that I have done for XMPP client in Flex with ActionScript 3.
For ActionScript 3, you must download XIFF API 3.0 from http://www.igniterealtime.org.
Here is the sample code that you can follow to create XMPP client in Flex with ActionScript 3.
For run this sample code, you must have account in XMPP Server like OpenFire or Ejabberd.

Create account name “sinal” and one more “lee” in XMPP Server.

MXML:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initApp()">
	
<mx:Script>
<!&#91;CDATA&#91;
	import mx.controls.Alert;
	private var xmpp:XMPPSocket = new XMPPSocket();
	public function initApp():void
	{
		btnConnect.addEventListener(MouseEvent.CLICK, connectEvent);
		btnConnect.addEventListener(KeyboardEvent.KEY_DOWN, connectEvent);	
		txtMsg.addEventListener(KeyboardEvent.KEY_UP, keyUp);		
	}
	
	public function connectEvent(event:Event):void
	{
		xmpp.onCreationComplete();		
	}
	
	public function messageSend():void
	{
		var msg:String = txtMsg.text; 
		var jid:String = "lee@seven-pc";
		xmpp.sendMessage(jid, msg);
		txtMsg.text = "";
	}
	
	public function keyUp(event:KeyboardEvent):void
        {        	
            switch(event.keyCode)
            {
                case Keyboard.ENTER :
                    messageSend();
                    break;
            }
        }
&#93;&#93;>
</mx:Script>

<mx:states>
	<mx:State name="ConnectedState">		
		<mx:AddChild relativeTo="{form1}" position="lastChild">
			<mx:VBox width="422" height="179" id="vbox1">
			<mx:TextArea width="422" height="145" id="textTalk">						
				</mx:TextArea>
				<mx:HBox>
					<mx:Label text="Message:"/>
					<mx:TextInput width="289" id="txtMsg" keyUp="keyUp(event)"/>
					<mx:Button label="Send" id="btnSend" click="messageSend()"/>
				</mx:HBox>
			</mx:VBox>
		</mx:AddChild>
		<mx:SetProperty target="{formitem1}" name="label" value="Status:"/>
		<mx:RemoveChild target="{formitem1}"/>
		<mx:AddChild relativeTo="{vbox1}" position="before" target="{formitem1}"/>
		<mx:RemoveChild target="{btnConnect}"/>
		<mx:AddChild relativeTo="{form1}" position="lastChild" target="{btnConnect}"/>
	</mx:State>
</mx:states>


<mx:Form width="455" height="263" id="form1" horizontalCenter="-28" verticalCenter="-29">
	<mx:FormItem label="Status:" id="formitem1">
		<mx:Text id="textStatus" text="Offline"/>
	</mx:FormItem>
	<mx:Button label="Connect" id="btnConnect"/>
</mx:Form>

</mx:Application>

ActionScript :

package
{
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.xml.XMLDocument;

import mx.core.Application;

import org.jivesoftware.xiff.conference.Room;
import org.jivesoftware.xiff.core.JID;
import org.jivesoftware.xiff.core.XMPPSocketConnection;
import org.jivesoftware.xiff.data.Message;
import org.jivesoftware.xiff.data.Presence;
import org.jivesoftware.xiff.events.IncomingDataEvent;
import org.jivesoftware.xiff.events.LoginEvent;
import org.jivesoftware.xiff.events.MessageEvent;
import org.jivesoftware.xiff.events.RoomEvent;
import org.jivesoftware.xiff.events.XIFFErrorEvent;

public class XMPPSocket{
	private var connection:XMPPSocketConnection;
	private var keepAlive:Timer;
	
	private var username:String = "sinal";
	private var password:String = "123456";
	private var server:String = "seven-pc";
	//private var textDisplay:TextArea = Application.application.textTalk;
	
	
	public function onCreationComplete():Boolean
	{
		connection = new XMPPSocketConnection();
		connection.username = username;
		connection.password = password;
		connection.server = server;
		connection.port = 5222;				
	
		connection.addEventListener(LoginEvent.LOGIN, onLogin);
	    connection.addEventListener(XIFFErrorEvent.XIFF_ERROR, onError);
	    connection.addEventListener(IncomingDataEvent.INCOMING_DATA, onIncomingData);
	    connection.addEventListener(MessageEvent.MESSAGE, onMessage);
	    
	    keepAlive = new Timer(2 * 60 * 1000);
        keepAlive.addEventListener(TimerEvent.TIMER, onKeepAliveLoop);
				
		return connection.connect("standard");
		
	}
	
	public function onIncomingData(event:IncomingDataEvent):void
    {
           var xml:XMLDocument = event.data;
           //Application.application.textTalk.text = Application.application.textTalk.text + "\n" + String(xml);		         
    }
	
	private function onLogin(e:LoginEvent):void
	{			
		if(connection.isLoggedIn()){			
			Application.application.textStatus.text = "Online";
			Application.application.btnConnect.enabled = false;
			Application.application.btnConnect.visible = false;
			Application.application.currentState = 'ConnectedState';
		}
		
		trace("onLogin. " + e.toString());	

        keepAlive.start();
       
        var presence:Presence = new Presence(null, connection.jid, Presence.SHOW_CHAT, null, null, 1);        
        connection.send(presence);
        
		/*var room:Room = new Room(connection);
		room.roomJID = new JID("lee@conference.seven-pc");
		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.errorMessage);
	}
	
	private function onKeepAliveLoop(event:TimerEvent):void
    {
            connection.sendKeepAlive();
    }
    
    
    public function sendMessage(jid:String, contentMsg:String):void
    {   	
    	var chattingWith:JID = new JID(jid);
    	var msg:Message = new Message(chattingWith, null, contentMsg, null, Message.CHAT_TYPE);
        if (connection.isLoggedIn())
        {
            connection.send(msg);
            addMessage(connection.jid, contentMsg);
        }       
    }
    
    private function onMessage(event:MessageEvent):void
    {
        trace("onMessage. " + event.toString());
        addMessage(event.data.from, event.data.body);
    }
    
    private function addMessage(from:JID, msg:String):void
    {
        var date:Date = new Date();
        Application.application.textTalk.text = Application.application.textTalk.text + "\n" + ("[" + date.getHours() + ":" + date.getMinutes() + " |  " + from.node + " ] " + msg);
    }
    
}
}

Connecting to external data services using flash lite

Leave a comment

Instant Messaging for Khmer Unicode

Leave a comment

Nowadays Cambodia Society has been transformed from the ancient style in exchange message from writing the message on the paper to email, because of this factor makes my friends and I want to share some contribution to the Cambodian people with the Khmer Unicode by sharing the knowledge in IT to develop one instant messaging for Khmer Unicode as soon as possible.My friend and I hope that this project will be supported by Cambodian people and the people who has ability to use Khmer Unicode.

KU-Chat will be coming soon.

Please comment us for help.

Chat with Jabber.org

Leave a comment

So far, I have used the chat with yahoo, google, skype and IRC. Fortunately now I have found one free chat service typically called Jabber Chat Service.
For Jabber Chat Service, you just go to http://jabber.org and set up one account for jabber id in order to communicate with other people who use XMPP protocol chat client like google.
And then you can use your jabber id with PSI XMPP chat client or other XMPP chat client like SamePlace, Gtalk and so on.

XMPP

Leave a comment

The XMPP service offered at jabber.org is the original and longest-running XMPP service on the Internet. In the beginning, the jabber.org service served as the development testbed for the jabberd server project. After the release of jabberd 1.0 in May 2000, the jabber.org service became more stable and thus more popular with end users. The userbase has continued to grow, from perhaps 500 users in late 1999 to over 500,000 users in April 2009. Clearly the service is no longer experimental, and considerable attention is needed to maintain an acceptable level of functionality and performance.
More detail