AMF 通信如何工作?

发布于 2024-08-04 06:53:03 字数 584 浏览 9 评论 0原文

Flash 如何通过 AMF 与服务器上的服务/脚本进行通信?

关于Python / Perl / PHP的AMF库比.NET更容易开发/Java:

  • 每当 Flash 发送远程过程调用时,它们是否执行脚本文件?
  • 或者它们通过套接字与作为服务运行的脚本类进行通信?

关于典型的 AMF 功能:

  • 数据如何传输?是通过自动序列化的方法参数吗?
  • 服务器如何“推送”给客户端? Flash 电影必须连接到插座吗?

感谢您抽出时间。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

辞慾 2024-08-11 06:53:03

我唯一熟悉的 AMF 库是 PyAMF,到目前为止,它的使用效果非常好。以下是您对 PyAMF 问题的回答:

  • 我想您可以将其作为脚本运行(您的意思是像 CGI 一样吗?),但最简单的 IMO 是专门为 AMF 请求设置一个应用服务器

  • 最简单的方法是在纯 python 中定义函数,PyAMF 包装它以序列化传入/传出 AMF 数据

  • 如果您需要的话,您可以通过套接字进行通信这样做,但同样,使用纯 Python 函数是最简单的;套接字的一种用途是保持开放连接并将数据“推送”到客户端,请参阅示例

这是一个在 localhost:8080 上提供三个简单 AMF 服务的示例:

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

我绝对会推荐 PyAMF。查看示例以了解它的功能以及代码的外观。

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.

月亮坠入山谷 2024-08-11 06:53:03

Flash 如何通过 AMF 与服务器上的服务/脚本进行通信?

数据通过 TCP/IP 连接传输。有时会使用现有的 HTTP 连接,而在其他情况下会为 AMF 数据打开新的 TCP/IP 连接。当打开 HTTP 或附加 TCP 连接时,可能会使用套接字接口。 AMF 肯定通过某种 TCP 连接进行传输,而套接字接口实际上是打开此类连接的唯一方法。

传输的“数据”由 ECMA 脚本 (Javascript(tm)) 数据类型组成,例如“整数”、“字符串”、“对象”等。

对于如何将对象编码为二进制的技术规范,Adobe 发布了一个规范: AMF 3.0 Spec at Adob​​e.com

一般来说,使用 AMF 的客户端/服务器系统的工作方式是这样的:

  1. 客户端显示一些用户界面并打开与服务器的 TCP 连接。
  2. 服务器向客户端发送一些数据,客户端更新其用户界面。
  3. 如果用户发出命令,客户端就会通过 TCP 连接向服务器发送一些数据。
  4. 继续步骤 2-3,直到用户退出。

例如,如果用户单击 UI 中的“发送邮件”按钮,则客户端代码可能会执行以下操作:

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

然后:

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

在服务器代码中,服务器还会监视连接以及传入的 AMF 对象。它接收消息,并将控制权传递给适当的响应函数。这称为“发送消息”。

有了更多关于您想要实现的目标的信息,我可以为您提供更多有用的详细信息。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文