<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>https://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>https://jackxiang.com/post//</link>
<title><![CDATA[flash-php的RPC方案amfphp　 ]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Tue, 29 Dec 2009 05:36:59 +0000</pubDate> 
<guid>https://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	flash-php的RPC方案amfphp　 <br/>时间：2009-03-04 17:13:18&nbsp;&nbsp;来源：http://ilovelate.blog.163.com/blog/static/601420091212142713&nbsp;&nbsp;作者： <br/>flash里自己有个二进制的数据传输协议Amf， 幸好php里有个amfphp,那就很方便了， 协议会自动转换php和flash的数据类型，本来都是动态语言，啥都好办。<br/>&nbsp;&nbsp;&nbsp;&nbsp;网址：http://www.amfphp.org/&nbsp;&nbsp; 官方的，目前最新版本1.9 beta2<br/>&nbsp;&nbsp;&nbsp;&nbsp;下载地址： http://sourceforge.net/project/showfiles.php?group_id=72483<br/>&nbsp;&nbsp; 另外要安装个可以提升性能的东东：http://www.teslacore.it/wiki/index.php?title=AMFEXT&nbsp;&nbsp;&nbsp;&nbsp;目前版本0.8.7<br/>&nbsp;&nbsp; 将amfphp放到php项目目录下就可以使用了。<br/>&nbsp;&nbsp;注意将Remote Service php 放到 amfphp&#92;services 目录里面就可以使用了，很简单。<br/><br/> 贴个session的例子：<br/>flash端：<br/><br/><br/><div class="code">// Wade Arnold: 1/6/2008<br/>// Example is designed to show how to use PHP sessions. <br/>package &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;// required for flash file and output display<br/>&nbsp;&nbsp;&nbsp;&nbsp;import flash.display.MovieClip;<br/>&nbsp;&nbsp;&nbsp;&nbsp;import fl.events.*;<br/>&nbsp;&nbsp;&nbsp;&nbsp;import flash.events.*;<br/>&nbsp;&nbsp;&nbsp;&nbsp;// required to send/recieve data over AMF<br/>&nbsp;&nbsp;&nbsp;&nbsp;import flash.net.NetConnection;<br/>&nbsp;&nbsp;&nbsp;&nbsp;import flash.net.Responder;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;// Flash CS3 Document Class. <br/>&nbsp;&nbsp;&nbsp;&nbsp;public class Counter extends MovieClip &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private var gateway:String = &quot;http://localhost/server/amfphp/gateway.php&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private var connection:NetConnection;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private var responder:Responder;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public function Counter() &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;trace(&quot;AMFPHP Session Counter Example&quot;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Event listner for buttons<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;increment_btn.addEventListener(MouseEvent.CLICK, incrementCounter);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reset_btn.addEventListener(MouseEvent.CLICK, resetCounter);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;destroy_btn.addEventListener(MouseEvent.CLICK, destroySession);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Responder to handle data returned from AMFPHP.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;responder = new Responder(onResult, onFault);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;connection = new NetConnection;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Gateway.php url for NetConnection<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;connection.connect(gateway);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Method run when the &quot;Increment Counter&quot; button is clicked. <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public function incrementCounter(e:MouseEvent):void &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Send the data to the remote server. <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;connection.call(&quot;Counter.increment&quot;, responder);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Method run when the &quot;Rest Counter&quot; button is clicked. <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public function resetCounter(e:MouseEvent):void &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Send the data to the remote server. <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;connection.call(&quot;Counter.unregister&quot;, responder);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Method run when the &quot;Destroy Session&quot; button is clicked. <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public function destroySession(e:MouseEvent):void &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Send the data to the remote server. <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;connection.call(&quot;Counter.destroy&quot;, responder);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Handle a successful AMF call. This method is defined by the responder. <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private function onResult(result:Object):void &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;response_txt.text = String(result);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Handle an unsuccessfull AMF call. This is method is dedined by the responder. <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private function onFault(fault:Object):void &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;response_txt.text = String(fault.description);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&#125;</div><br/>php端：<br/><div class="code"><br/>&lt;?php<br/>// Wade Arnold: 1/6/2008<br/>// Example is designed to show how to use PHP sessions. <br/>class Counter &#123;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;public function __construct() &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Check if the session is available or create it. <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!isset($_SESSION&#91;&#039;count&#039;&#93;)) &#123;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$_SESSION&#91;&#039;count&#039;&#93; = 0;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;// Used to increment the session variable count. <br/>&nbsp;&nbsp;&nbsp;&nbsp;public function increment() &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$_SESSION&#91;&#039;count&#039;&#93;++;<br/>&nbsp;&nbsp;&nbsp;&nbsp;return $_SESSION&#91;&#039;count&#039;&#93;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;// used to destroy the session variable and start over. <br/>&nbsp;&nbsp;&nbsp;&nbsp;public function unregister() &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unset($_SESSION&#91;&#039;count&#039;&#93;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;return true;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;// remove the entire session from the server. <br/>&nbsp;&nbsp;&nbsp;&nbsp;public function destroy() &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;session_destroy();<br/>&nbsp;&nbsp;&nbsp;&nbsp;return true;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&#125;<br/>?&gt;</div><br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; YY两句，看到热血三国的通讯方式竟然是amfphp的RPC通讯方式的， 这样的话编程模型跟普通的web项目开发就一模一样了， 现在只是说使用了flash界面而已，开发难度大幅度降低。<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;想想也是， 策略类的游戏，没必要使用客户端游戏的那种socket编程模型，开发起来复杂多了。 可能游戏玩法不一样引起的。如果是有实时战斗的玩法，那必须得socket编程了吧。&nbsp;&nbsp;<br/>
]]>
</description>
</item><item>
<link>https://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] flash-php的RPC方案amfphp　 ]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>