LAZIOMATICA – Guida allo Sviluppo Software

La nuova forma del software su misura…

 

Adobe AIR: un semplice player per lo streaming live di Flash Media Server

Avevo l’esigenza di testare dei canali streaming pubblicati da un FMS ed ho implementato questo semplice client con funzionalità di debug di cui allego il codice.

<?xml version=”1.0″ encoding=”utf-8″?>
<mx:WindowedApplication xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute” creationComplete=”{init()}” width=”560″ height=”474″ borderColor=”#1A41C0″ backgroundGradientAlphas=”[1.0, 1.0]” backgroundGradientColors=”[#123BB3, #03097F]“>
<mx:Script>
<![CDATA[
import mx.messaging.channels.AMFChannel;
import mx.utils.ObjectUtil;
private var meta:Object;
public var nc : NetConnection ;
public var ns : NetStream ;
public var video: Video = new Video;

private function init () : void {

nc = new NetConnection ()
nc.objectEncoding = ObjectEncoding.AMF3 ;
nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus ) ;
nc.addEventListener( AsyncErrorEvent.ASYNC_ERROR, onAsyncError ) ;
nc.addEventListener(IOErrorEvent.IO_ERROR, onIOError ) ;
nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecError ) ;

nc.connect( "rtmp://www.serverflash.xxx/live/"); // url del server FMS
}

private function onNetStatus ( e : NetStatusEvent ) : void {
var nsClient:Object = {};
nsClient.onMetaData = ns_onMetaData;
nsClient.onCuePoint = ns_onCuePoint;
trace ( e.info.code ) ;

//-- if is connected
if ( e.info.code.indexOf("Success") > -1  ){
ns = new NetStream (nc ) ;
ns.addEventListener(NetStatusEvent.NET_STATUS, onNsStatus )

ns.client = nsClient;
ns.play("myStream"); // nome dello Stream
video = new Video();
video.attachNetStream(ns);
//panelVideo.addChild(video);

uic.addChild(video);

}
}

private function onAsyncError ( e : AsyncErrorEvent ) : void {
trace (e.text ) ;
}

private function onIOError ( e : IOErrorEvent ) : void {
trace ( e.text ) ;
}

private function onSecError ( e : SecurityErrorEvent ) : void {
trace ( e.text ) ;
}

private function onNsStatus ( e : NetStatusEvent ) : void {

trace ( "netstatus------>" + e.info.code ) ;
}

private function ns_onMetaData(item:Object):void {
trace("meta");
meta = item;
video.width = item.width;
video.height = item.height;

//panel.title = "framerate: " + item.framerate;
panel.visible = true;
trace(ObjectUtil.toString(item));
}
private function ns_onCuePoint(item:Object):void {
trace("cue");
}
]]>
</mx:Script>

<mx:Panel id=”panel” visible=”true” horizontalAlign=”center” title=”Video Stream” left=”80″ right=”80″ bottom=”58″ top=”46″>
<mx:UIComponent id=”uic”  width=”345″ height=”246″/>
<mx:ControlBar>
<mx:Button label=”Play/Pause” click=”ns.togglePause();” />
<mx:Button label=”Rewind” click=”ns.seek(0); ns.pause();”  enabled=”false”/>
</mx:ControlBar>
</mx:Panel>
<mx:Label x=”435″ y=”10″ text=”InfoDesk” color=”#DEF3F7″ fontWeight=”bold” fontSize=”18″/>
</mx:WindowedApplication>

Filed under : Actionscript 3,AIR,Flash Media Server,Flex,RIA
By admin
On 13 febbraio 2009
At 13:04
Comments : 0
 
 

Flex Developer toolbox

Here a few of useful tools, framework and library  for a fast build of rich internet application with Flex:

Tools

- Flex Builder (Plugin): Adobe® Flex™ Builder™ 2 is an Eclipse™ based IDE for developing rich Internet applications (RIAs) with the Adobe Flex framework.
- Eclipse: an open source community whose projects are focused on building an open development platform
- Ant: a Java-based build tool. In theory, it is kind of like Make, but without Make’s wrinkles.
- Flex Ant Tasks: provide a convenient way to build your Flex projects using an industry-standard build management tool.
- ASDoc: a command-line tool that you can use to create API language reference documentation as HTML pages from the classes in your Flex application.
- Cruise Control: a framework for a continuous build process. It includes, but
is not limited to, plugins for email notification, Ant, and various source control tools.

Frameworks

- Cairngorm: a lightweight yet prescriptive framework for rich Internet application (RIA) development.
- PureMVC: a lightweight framework for creating applications in ActionScript 3, based upon the classic Model-View-Controller design meta-pattern
- Prana: an Inversion of Control (IoC) Container for the Flex Framework

Unit Testing

- FlexUnit: a unit testing framework for Flex and ActionScript 3.0 applications. It mimics the functionality of JUnit, a Java unit testing framework, and comes with a graphical test runner.
- Flex Unit Optional Ant Task: Allows you to hook FlexUnit into a Cruise Control cycle and extract test reports

Libraries

- Corelib: consists of several basic utilities for MD5 hashing, JSON serialization, advanced string and date parsing, and more.
- Flexlib: a community effort to create open source user interface components for Adobe Flex 2

Remote Gateways

- WebORB: facilitates connectivity between rich clients created with Flex, Flash or AJAX and server-side applications developed with .NET, Java, Ruby on Rails, PHP or XML Web Services.

- Fluorine: an open source .NET Flash Remoting Gateway.

- AMFPHP: a free open-source PHP implementation of the Action Message Format(AMF). AMF allows for binary serialization of Action Script (AS2, AS3) native types and objects to be sent to server side services.

- BlazeDS: is the server-based Java remoting and web messaging technology that enables developers to easily connect to back-end distributed data and push data in real-time to Adobe® Flex® and Adobe AIR™ applications for more responsive rich Internet application (RIA) experiences.

Filed under : Actionscript 3,AIR,Data Remoting,Flex
By admin
On 24 gennaio 2009
At 21:14
Comments : 0
 
 

BlazeDS: Adobe Opensource Data Remoting – Performance Benchmark

Filed under : AIR,Data Remoting,Flex,RIA
By admin
On
At 20:53
Comments : 0
 
 

AS3 – XML Socket & Binary Socket

There are two different types of socket connections possible in ActionScript 3.0: XML socket connections and binary socket connections. An XMLsocket lets you connect to a remote server and create a server connection that remains open until explicitly closed. This lets you exchange XML data between a server and client without having to continually open new server connections. Another benefit of using an XML socket server is that the user doesn’t need to explicitly request data. You can send data from the server without requests, and you can send data to every client connected to the XML socket server.

ActionScript provides a built-in XMLSocket class, which lets you open a continuous connection with a server. This open connection removes latency issues and is commonly used for real-time applications such as chat applications or multiplayer games. A traditional HTTP-based chat solution frequently polls the server and downloads new messages using an HTTP request. In contrast, an XMLSocket chat solution maintains an open connection to the server, which lets the server immediately send incoming messages without a request from the client.
To create a socket connection, you must create a server-side application to wait for the socket connection request and send a response to the SWF file. This type of server-side application can be written in a programming language such as Java, Python, or Perl. To use the XMLSocket class, the server computer must run a daemon that understands the protocol used by the XMLSocket class. The protocol is described in the following list:

* XML messages are sent over a full-duplex TCP/IP stream socket connection.
* Each XML message is a complete XML document, terminated by a zero (0) byte.
* An unlimited number of XML messages can be sent and received over a single XMLSocket connection.

The XMLSocket class cannot tunnel through firewalls automatically because, unlike the Real-Time Messaging Protocol (RTMP), XMLSocket has no HTTP tunneling capability. If you need to use HTTP tunneling, consider using Flash Remoting or Flash Media Server (which supports RTMP) instead.

You can use the XMLSocket.connect() and XMLSocket.send() methods of the XMLSocket class to transfer XML to and from a server over a socket connection. The XMLSocket.connect() method establishes a socket connection with a web server port. The XMLSocket.send() method passes an XML object to the server specified in the socket connection.

When you invoke the XMLSocket.connect() method, Flash Player opens a TCP/IP connection to the server and keeps that connection open until one of the following occurs:

* The XMLSocket.close() method of the XMLSocket class is called.
* No more references to the XMLSocket object exist.
* Flash Player exits.
* The connection is broken (for example, the modem disconnects).

Example of Socket Server in Java:

import java.io.*;
import java.net.*;

class SimpleServer
{
private static SimpleServer server;
ServerSocket socket;
Socket incoming;
BufferedReader readerIn;
PrintStream printOut;

public static void main(String[] args)
{
int port = 8080;

try
{
port = Integer.parseInt(args[0]);
}
catch (ArrayIndexOutOfBoundsException e)
{
// Catch exception and keep going.
}

server = new SimpleServer(port);
}

private SimpleServer(int port)
{
System.out.println(“>> Starting SimpleServer”);
try
{
socket = new ServerSocket(port);
incoming = socket.accept();

readerIn = new BufferedReader(new InputStreamReader(incoming.getInputStream()));
printOut = new PrintStream(incoming.getOutputStream());
printOut.println(“Enter EXIT to exit.\r”);
out(“Enter EXIT to exit.\r”);
boolean done = false;
while (!done)
{
String str = readerIn.readLine();
if (str == null)
{
done = true;
}
else
{
out(“Echo: ” + str + “\r”);
if(str.trim().equals(“EXIT”))
{
done = true;
}
}
incoming.close();
}
}
catch (Exception e)
{
System.out.println(e);
}
}

private void out(String str)
{
printOut.println(str);
System.out.println(str);
}

AS3 snippet code for connect to server:

var xmlsock:XMLSocket = new XMLSocket();
xmlsock.connect(“127.0.0.1″, 8080);
}

to Receive data we add a listener on XMLSOCK:

xmlsock.addEventListener(DataEvent.DATA, onData);
private function onData(event:DataEvent):void
{
trace(“[" + event.type + "] ” + event.data);
}

to Send DATA we use the “send” method and pass an XML object or string:

xmlsock.send(xmlFormattedData);

Filed under : AIR,Flex,RIA
By admin
On 12 gennaio 2009
At 20:58
Comments : 0
 
 

Actionscript 3 MySql Driver – asSQL

asSQL is an Actionscript 3 Mysql Driver aimed towards AIR projects to allow Mysql database connectivity directly from Actionscript.

download from code.google.com

How to Use – example 1:

import com.maclema.mysql.Statement;
import com.maclema.mysql.Connection;
import com.maclema.mysql.ResultSet;
import mx.controls.Alert;
import mx.rpc.AsyncResponder;
import com.maclema.mysql.MySqlToken;
import com.maclema.util.ResultsUtil;

//The MySql Connection
private var con:Connection;

private function onCreationComplete():void {
con = new Connection(“localhost”, 3306, “root”, “”, “assql-test”);
con.addEventListener(Event.CONNECT, handleConnected);
con.connect();
}

private function handleConnected(e:Event):void {
var st:Statement = con.createStatement();

var token:MySqlToken = st.executeQuery(“SELECT * FROM employees”);

token.addResponder(new AsyncResponder(
function(data:Object, token:Object):void {
var rs:ResultSet = ResultSet(data);
Alert.show(“Found ” + rs.size() + ” employees!”);
},

function(info:Object, token:Object):void {
Alert.show(“Error: ” + info);
},

token
));
}

How to Use example 2:

import com.maclema.mysql.Statement;
import com.maclema.mysql.Connection;
import com.maclema.mysql.ResultSet;
import mx.controls.Alert;
import mx.rpc.AsyncResponder;
import com.maclema.mysql.MySqlToken;
import com.maclema.util.ResultsUtil;

//The MySql Connection
private var con:Connection;

private function onCreationComplete():void {
con = new Connection(“localhost”, 3306, “root”, “”, “assql-test”);
con.addEventListener(Event.CONNECT, handleConnected);
con.connect();
}

private function handleConnected(e:Event):void {
getAllEmployees();
}

private function getAllEmployees():void {
var st:Statement = con.createStatement();

var token:MySqlToken = st.executeQuery(“SELECT * FROM employees”);
token.info = “GetAllEmployees”;
token.addResponder(new AsyncResponder(result, fault, token));
}

private function getEmployee(employeeID:int):void {
var st:Statement = con.createStatement();
st.sql = “SELECT * FROM employees WHERE employeeID = ?”;
st.setNumber(1, employeeID);

var token:MySqlToken = st.executeQuery();
token.info = “GetEmployee”;
token.employeeID = employeeID;
token.addResponder(new AsyncResponder(result, fault, token));
}

private function result(data:Object, token:Object):void {
var rs:ResultSet;

if ( token.info == “GetAllEmployees” ) {
rs = ResultSet(data);
Alert.show(“Found ” + rs.size() + ” employees!”);
}
else if ( token.info == “GetEmployee” ) {
rs = ResultSet(data);
if ( rs.next() ) {
Alert.show(“Employee ” + token.employeeID + ” username is ‘” + rs.getString(“username”) + “‘”);
}
else {
Alert.show(“No such employee for id ” + token.employeeID);
}
}
}

private function fault(info:Object, token:Object):void {
Alert.show(token.info + ” Error: ” + info);
}

Filed under : AIR,Flash CS3,Flex,RIA
By admin
On
At 20:46
Comments :Commenti disabilitati