amf

13
AMF來搭起美麗的橋樑 高見龍

Upload: eddie-kao

Post on 06-May-2015

2.193 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: AMF

用AMF來搭起美麗的橋樑

高見龍

Page 2: AMF

高見龍http://blog.eddie.com.twaquarianboy@ptt [email protected]@plurkeddiekao@facebook

Page 3: AMF
Page 4: AMF

AMF = Action Message Formatneither “A”dobe nor “A”ctionscript(雖然它是由Adobe制定的)

Page 5: AMF

wiki上的解釋Action Message Format (AMF) is a binary format used to serialize ActionScript objects. It is used primarily to

exchange data between an Adobe Flash application and a remote service, usually over the internet.

Page 6: AMF

支援各種程式語言.NET - FluorineFx (LGPL)

PHP - AMFPHP, Zend_Amf, CakeAMFPHPPython - PyAMF, DjangoAMF

Perl - AMF::PerlRuby - RubyAMF

...

其它內容可參閱 http://en.wikipedia.org/wiki/Action_Message_Format

Page 7: AMF

PHP

Page 8: AMF

1. 下載AMFPHP(目前是1.9版)http://amfphp.sourceforge.net/

2. 把下載下來的壓縮檔解開,放在自己找得到的路徑就行了例如: http://127.0.0.1/test/amfphp/

3. 順利的話應該可以看到一個Service Browser(flex寫的)連結: http://127.0.0.1/test/amfphp/browser

4. 在AMF gateway上新增一個服務(放到services資料夾裡)<?phpclass callme{ function callmeplease($text) { return $text; }}

5. 重新整理service browser,應該可看到寫寫新增的內容

中文支援問題:開啟AMFPHP資料夾的gateway.php,應該可以找到一段跟字碼有關的:$gateway->setCharsetHandler("utf8_decode", "ISO-8859-1", "ISO-8859-1");

修改成:$gateway->setCharsetHandler("utf8_decode", "UTF-8", "UTF-8");

或是如果你的PHP模組裡有iconv的話也可以這樣改:$gateway->setCharsetHandler("iconv","UTF-8","UTF-8");

參考資料:http://blog.eddie.com.tw/2008/10/12/amfphp-tutorial

使用方法

Page 9: AMF

Django

Page 10: AMF

1. 下載PyAMF(Stable版本 0.51)http://pyamf.org/community/download.html

2. 解壓縮後,進到資料夾裡執行setup.py或是ez_install進行安裝

3. 為展示目的,建立一個新的django project參考資料 http://www.eddie.com.tw/course/index.php/Django_index

4. 為展示目的,建立一個新的django app,準備新增AMF servicefrom pyamf.remoting.gateway.django import DjangoGateway

def amfdemo(req, text): return 'hello from pyamf : ' + textservices = { 'callme.callmeplease': amfdemo,}

AMFGateway = DjangoGateway(services, debug=True)

5. 修改urls.confurl(r'^gateway/$', 'demoamf.dddd.views.AMFGateway')

使用方法

Page 11: AMF

Ruby on Rails

Page 12: AMF

1. 使用RubyAmf pluginhttp://github.com/victorcoder/rubyamf_plugin

2. 為展示目的,建立一個新的RoR project,並進到project中安裝plugin(以rails 2.3.8為例)script/plugin install git://github.com/victorcoder/rubyamf_plugin.git

3. 安裝成功的話,可看見rubyamf的logohttp://127.0.0.1:3000/rubyamf/gateway/

4. 為展示目的,建立一個controller,並準備新增AMF serviceclass DemoamfController < ApplicationController def callmeplease render :amf => "hello from rubyamf : " + params[0] endend

5. 預設的呼叫方法為ControllerName.ActionName例如: DemoamfController.callmeplease

參考資料:http://blog.eddie.com.tw/2010/03/18/rubyamf

使用方法

Page 13: AMF

Thank You!2010/10/27

ADcube Network, Inc.TEL +886-2-2370-0085 ext.501FAX +886-2-2370-0125

9F., No.43, Sec. 1, Chongqing S. Rd., Zhongzheng District, Taipei City 100, Taiwan (R.O.C.)

Welcome to visit http://www.adcube.com.tw for more information!