IT Community - Software Programming, Web Development and Technical Support

Flash Remoting

This is a discussion on Flash Remoting within the Flash Actionscript Programming forums, part of the Web Development category; Flash Remoting Flash Remoting allows flash movies to call remote server side applications, passing parameters and recieving requests, without knowledge ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > Flash Actionscript Programming

Register FAQ Members List Calendar Mark Forums Read
  #1  
Old 03-19-2007, 10:36 PM
nssukumar nssukumar is offline
D-Web Sr.Programmer
 
Join Date: Feb 2007
Posts: 155
nssukumar is on a distinguished road
Default Flash Remoting

Flash Remoting

Flash Remoting allows flash movies to call remote server side applications, passing parameters and recieving requests, without knowledge of the server side. The calls are usually named Remote Procedural Calls (RPCs), and transfer serialized, type-persistent objects directly between the server and a Flash MX client. Developers on both sides (flash and server) collaberate on ways of calling methods in order to build the system. With AMF (Action Message Format) the exchange of information is faster and allows you to pass objects (not only name/value pairs) between Flash and the server in binary format. This allows you to easily develop complex applications that rely on an efficient way of sending and recieving data
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2  
Old 03-20-2007, 12:22 AM
Karpagarajan Karpagarajan is offline
D-Web Analyst
 
Join Date: Mar 2007
Posts: 301
Karpagarajan is on a distinguished road
Thumbs up Re: Flash Remoting

This is an excellent feature in flash.The main advantage of Flash remoting is we can get the server side data types(for example, video, recordset etc) to the client side flash component. I was really wonder about this feature when I used in my FLASH component.

I have given the following information to understand about the Flash Remoting.

Flash Remoting Process

The Flash Remoting gateway is installed on the application server and acts as an interface between the Flash Player and the server. The Flash Remoting software that implements the gateway is also called an adapter. It has three main tasks:
  • Handle requests from the Flash Player to remote services. These services can be on the same server as the Flash Remoting gateway or can be external to the server in the form of web services.
  • Translate requests and data from the Flash Player into server-side requests and datatypes.
  • Translate responses and data from the server into native ActionScript datatypes.
Communication between the Flash Player and the Flash Remoting gateway is done via HTTP, which has a few implications:

Communication between the Flash Player and the Flash Remoting gateway is request-driven. The Flash Player must initiate all communication with the Flash Remoting gateway. The server cannot push data to Flash unless it is requested by the Flash Player. Use the ActionScript XMLSocket object in ActionScript for Flash MX if you need to push data from the server to Flash, such as in a chat application. Another option is to use Macromedia’s Flash Communication Server MX (FlashCom) for these types of applications.

HTTP is a stateless protocol, so each request from the Flash Player opens a new connection to the server. The Flash Remoting gateway automatically maintains state between requests through the use of cookies. If cookies are not available on the client, the session state is maintained through a header in the communication packets between the Flash Player and server.

Protocols that work with HTTP, such as SSL, also work with Flash Remoting.
the client/server architecture is the same when the Flash Player communicates with Flash Remoting via HTTPS or SSL as it is using
HTTP. Support for HTTPS allows communication between the Flash Player and
the server to be encrypted using SSL, provided that the Flash movie is delivered to the client over an SSL connection and displayed within an SSL-enabled browser. This gives a Flash application the same level of security that is available to the HTML application.

What is AMF?

Action Message Format

Flash 5 movies could send XML or name/value pairs across HTTP. Although these packets could be parsed automatically by Flash or manually by the developer using custom ActionScript, parsing could be slow because all XML data is sent as text strings encased by cumbersome tags. Flash Remoting is able to handle complex datatypes, such as objects, structures, arrays, and recordsets. A proprietary format was needed to transfer information back and forth between the Flash movie and the application server.
The protocol used for communication between the Flash Remoting gateway and the Flash Player is Action Message Format (AMF). AMF is a binary protocol designed by Macromedia to provide a lightweight, efficient means to serialize, deserialize, and transport data between the Flash Player and the Flash Remoting gateway.

It is not necessary to understand AMF in detail to develop robust Flash applications that utilize Flash Remoting; however, it is useful to have a basic understanding of the protocol. Macromedia has not documented the protocol publicly, but the HTTP packets can be examined to gain insight into the format, which seems to be closely based on the format used in remote shared objects (RSOs). The developers of the AMFPHP project have partially documented the format at:

The Flash Player communicates with the Flash Remoting gateway via the AMF protocol sent via standard HTTP requests. An AMF packet is sent as a binary POST with the body of the request containing the binary data serialization and remote procedure call information.

AMFPHP
Amfphp is an RPC toolkit for PHP. It allows seamless communication between Php and :
• Flash and Flex with Remoting
• JavaScript and Ajax with JSON
• XML clients with XML-RPC

Here is the sample program to make use of the AMFPHP.

PHP Service

Several remote methods are defined in this service. Focusing on the getOrderList function, we have:

<?php
class pizzaService {
var $ordertable = "amfphp_orders"; // the orders table
var $pizzatable = "amfphp_pizzas"; // the pizzas table
/* mysql_connect and mysql_select_db are in the constructor */
function getOrderList ()
{
$sql = "SELECT o.order_id as orderid, o.order_status as status, o.order_name as name, p.pizza_id as pizzaid, p.pizza_details as details, p.pizza_quantity as quantity FROM $this->ordertable o, $this->pizzatable p WHERE o.order_id = p.order_id AND o.order_status=1 ORDER BY o.order_time";
return mysql_query($sql);
}

/* Other methods below */}
?>


The ActionScript code for getting the order list looks like the following:

import mx.remoting.*;
import mx.rpc.*;

var gatewayUrl:String = "http://amfphp.org/amfphp/gateway.php";
service = new Service(gatewayUrl, null, "pizzaService");

var pc:PendingCall = service.getOrderList();
pc.responder = new RelayResponder(this, "handleGetOrderList", null);

function handleGetOrderList(re:ResultEvent)
{
var rs:RecordSet = RecordSet(re.result);
for(var i = 0; i < rs.length; i++) {
var item = rs.getItemAt(i);
//item is an object with keys orderid, status, etc.
}
}


The resource returned by MySQL query is automatically converted to the corresponding ActionScript type, mx.remoting.RecordSet. You didn't have to loop through your query, you didn't have to explode URL-encoded strings on a pipe (|) separator, you didn't have to write code to generate XML, you didn't have to use xml.firstChild.firstChild.firstChild.childNodes[i].
What if we wanted to send an argument to the remote method? Then we would simply call service.getOrderList(firstArg). firstArg could be a string, a number, an array, or an object, and we would receive the corresponding types in php. As you can see, you don't have to worry about serializing and deserializing your data, instantiating your class, or making sure the method exists before calling this, as amfphp does all of this for you.

Hope it will be useful for you also.

Thanks
__________________
Karpagarajan. R
Necessity is the mother of invention
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3  
Old 03-20-2007, 12:40 AM
nssukumar nssukumar is offline
D-Web Sr.Programmer
 
Join Date: Feb 2007
Posts: 155
nssukumar is on a distinguished road
Default Re: Flash Remoting

hi,
thanks a lot for the scenario that you had posted regarding flash remoting.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4  
Old 03-20-2007, 04:28 AM
Karpagarajan Karpagarajan is offline
D-Web Analyst
 
Join Date: Mar 2007
Posts: 301
Karpagarajan is on a distinguished road
Thumbs up Re: Flash Remoting

Why does Flash Remoting use AMF instead of SOAP to communicate with the FlashPlayer?

After all, SOAP was designed as a lightweight protocol for the exchange of information in a distributed environment, which sounds similar to the goals for AMF. Both SOAP and AMF can transfer data and make calls on remote services, and both work over standard HTTP and HTTPS.

There are several reasons why Macromedia developed AMF instead of using SOAP:
• SOAP is implemented as XML and is therefore rather verbose compared to the binary AMF.
• AMF is designed and optimized to work with Flash ActionScript datatypes. Deserializing AMF in the Flash Player is much more efficient than parsing and deserializing SOAP, because AMF has direct support for ActionScript datatypes whereas SOAP is a general-purpose protocol. Even if SOAP messages were compressed, serialization in AMF would still be more efficient.
• Adding AMF support to Flash Player 6 required only a small increase in the Player size (about 4 KB compressed), maintaining its slim footprint.
• Integrating full SOAP support on the client side, with acceptable performance, requires an increase in Player size. Although Flash Player 6 includes XML support, it does not support some headers required by SOAP. Using Flash Remoting, Flash can access SOAP-based web services even though Flash Player 6 doesn’t support SOAP directly. That is, the Flash Remoting gateway translates SOAP requests to and from AMF format on the server-side and then uses AMF to communicate with the Flash Player.Flash Player 7 supports SOAP directly,but it will be late 2004 until Flash Player 7 is widely distributed.

thanks
__________________
Karpagarajan. R
Necessity is the mother of invention
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
When would we use .NET Remoting and when Web services? krishnakumar ASP and ASP.NET Programming 8 04-12-2008 12:13 AM
.NET Remoting S.Vinothkumar C# Programming 14 10-04-2007 06:41 AM
security measures for .NET Remoting Arun ASP and ASP.NET Programming 1 08-17-2007 11:15 PM
What is .NET Remoting ? oxygen ASP and ASP.NET Programming 4 08-08-2007 01:37 AM
What are the situations we have to use a Web Service and Remoting in projects in asp. oxygen ASP and ASP.NET Programming 1 07-26-2007 03:00 AM


All times are GMT -7. The time now is 11:17 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
One Way Moving Companies | Stamford Dentist | Euro Millions Lottery | Home Loans| Furniture

SEO by vBSEO 3.0.0