Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does AMF communication work?

How does Flash communicate with services / scripts on servers via AMF?

Regarding the AMF libraries for Python / Perl / PHP which are easier to develop than .NET / Java:

  • do they execute script files, whenever Flash sends an Remote Procedure Call?
  • or do they communicate via sockets, to script classes that are running as services?

Regarding typical AMF functionality:

  • How is data transferred? is it by method arguments that are automatically serialised?
  • How can servers "push" to clients? do Flash movies have to connect on a socket?

Thanks for your time.

like image 752
Robin Rodricks Avatar asked Dec 17 '22 06:12

Robin Rodricks


2 Answers

The only AMF library I'm familiar with is PyAMF, which has been great to work with so far. Here are the answers to your questions for PyAMF:

  • I'd imagine you can run it as a script (do you mean like CGI?), but the easiest IMO is to set up an app server specifically for AMF requests

  • the easiest way is to define functions in pure python, which PyAMF wraps to serialize incoming / outgoing AMF data

  • you can communicate via sockets if that's what you need to do, but again, it's the easiest to use pure Python functions; one use for sockets is to keep an open connection and 'push' data to clients, see this example

Here's an example of three simple AMF services being served on localhost:8080:

from wsgiref import simple_server
from pyamf.remoting.gateway.wsgi import WSGIGateway

## amf services ##################################################

def echo(data):
    return data

def reverse(data):
    return data[::-1]

def rot13(data):
    return data.encode('rot13')

services = {
    'myservice.echo': echo,
    'myservice.reverse': reverse,
    'myservice.rot13': rot13,
}

## server ########################################################

def main():
    app = WSGIGateway(services)

    simple_server.make_server('localhost', 8080, app).serve_forever()

if __name__ == '__main__':
    main()

I would definitely recommend PyAMF. Check out the examples to see what it's capable of and what the code looks like.

like image 64
Steven Kryskalla Avatar answered Dec 27 '22 13:12

Steven Kryskalla


How does Flash communicate with services / scripts on servers via AMF?

Data is transferred over a TCP/IP connection. Sometimes an existing HTTP connection is used, and in other cases a new TCP/IP connection is opened for the AMF data. When the HTTP or additional TCP connections are opened, the sockets interface is probably used. The AMF definitely travels over a TCP connection of some sort, and the sockets interface is practically the only way to open such a connection.

The "data" that is transferred consists of ECMA-script (Javascript(tm)) data types such as "integer", "string", "object", and so on.

For a technical specification of how the objects are encoded into binary, Adobe has published a specification: AMF 3.0 Spec at Adobe.com

Generally the way an AMF-using client/server system works is something like this:

  1. The client displays some user interface and opens a TCP connection to the server.
  2. The server sends some data to the client, which updates its user interface.
  3. If the user makes a command, the client sends some data to the server over the TCP connection.
  4. Continue steps 2-3 until the user exits.

For example, if the user clicks a "send mail" button in the UI, then the client code might do this:

public class UICommandMessage extends my.CmdMsg
{
   public function UICommandMessage(action:String, arg: String)
   {
      this.cmd = action;
      this.data = String;
   }
}

Then later:

UICommandMessage msg = new UICommandMessage("Button_Press", "Send_Mail");
server_connection.sendMessage(msg);

in the server code, the server is monitoring the connection as well for incoming AMF object. It receives the message, and passes control to an appropriate response function. This is called "dispatching a message".

With more information about what you are trying to accomplish, I could give you more useful details.

like image 33
Heath Hunnicutt Avatar answered Dec 27 '22 14:12

Heath Hunnicutt