php - AMFPHP: Serializing Flash Objects over HTTP without the gateway -
flash + amfphp great combination. there cases, when flash remoting netconnection isn't right tool, various reasons. rob had great post on time ago: http://www.roboncode.com/articles/144
he has nice example on how deliver amf http request, without post , amf-request package call function netconnection sends, using zend_amf.
// include zend loader include_once 'zend/loader.php'; // tell zend loader autoload classes need // zend framework amf package zend_loader::registerautoload(); // create simple data structure $data = array('message' => 'hello, world!'); // create instance of amf output stream $out = new zend_amf_parse_outputstream(); // serialize our content amf3 example // alternatively serialize amf0 legacy // flash applications. $s = new zend_amf_parse_amf3_serializer($out); $s->writeobject($data); // return content (we have found newline needed // in order process data correctly on client side) echo "\n" . $out->getstream();
i approach , hapy replicate amfphp. why amfphp, ask? 'newest' version uses amf-ext, c php extension, serialize , deserialize data. faster php way zendamf still using.
of course played around amfphp , tried build necessary objects , use serializer class. got valid amf string, real data wrapped 'method package' told receiver answer 'service.method' call.
so there way serialize flash objects directly, without gateway , method wrapper, in amfphp?
thanks.
okay, got work now.
it's little bit more complicated zend_amf solution, faster. here code:
$data = array('message' => 'hello, world!'); // create gateway , configure $amf = new gateway(); amf_server::$encoding = 'amf3'; amf_server::$disabledebug = true; // construct body $body = new messagebody("...", "/1", array()); $body->setresults($data); $body->responseuri = $body->responseindex . "..."; // create object , add body $out = new amfobject(); $out->addbody($body); // serializer , use $serializer = new amfsimpleserializer(); $result = $serializer->serialize($out);
as see there new class amfsimpleserializer
built:
class amfsimpleserializer extends amfserializer { function serialize(&$amfout) { $encodecallback = array(&$this,"encodecallback"); $body = &$amfout->getbodyat(0); $this->outbuffer = ""; $this->outbuffer .= amf_encode($body->getresults(), $this->encodeflags, $encodecallback); $this->outbuffer = substr($this->outbuffer, 1); return $this->outbuffer; } }
this class works if amfext installed, modded use php enocding process. didn't implement it, because built on heavily modified version of amfphp.
i hope replaced classes code there real amfphp counterparts. i'll try test tomorrow , update answer if necessary.
after finished recognized nothing amfphp left in class, it's call amf_encode , deletion of first byte client can understand gets.
easy, simple, fast.
Comments
Post a Comment