Welcome, Guest. Please login or register.
Did you miss your activation email?
02/07/12, 09:16
Home Help Search Login Register
News: Parsley Flex framework review featuring quiz application, in our Flex frameworks series
Flex SDK 4.5 mobile roadmap: begin with your mobile development
Swiz Flex framework review featuring quiz application
New homepage we release our new Homepage, take a look ...

+  Flash-db
|-+  Server side Scripting and Database Support
| |-+  Flash Remoting with AMF (Moderators: Flash-db, Musicman, Jorge Solis, papachan, nothingGrinder)
| | |-+  AMF / Flash remoting for PHP (Musicman!)
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: 1 2 [3] 4 5 6 Print
Author Topic: AMF / Flash remoting for PHP (Musicman!)  (Read 123842 times)
Roberto
Server what's that
*
Posts: 1



View Profile Email
« Reply #30 on: 01/16/03, 11:59 »

Hi Musicman

That is really great stuff ! I am a Java developer and have used XML-RPC so far for flash communicating with the serverside. Propietary Macromedia Flash Remoting sucks, because I need to adapt and integrate that stuff in a Web Framework.
I am porting your PHP Class to Java, but have one question: how are numbers represented in AMF and what do the last two lines in getnumbers do ?

function getnumber($d, &$n)
   {      .......

      $zz = unpack("dflt", $ibf);
      return $zz['flt'];
   }

thanks in advance

Roberto

P.S.: Is there anywherer a AMF protocol specification around ?
Logged
justin
Server what's that
*
Posts: 6



View Profile Email
« Reply #31 on: 01/16/03, 12:06 »

I can see that their doubles so you should be able to do inputStream.readDouble.

Logged
Musicman
Administrator
Systems Administrator
*****
Posts: 2685



View Profile WWW Email
« Reply #32 on: 01/16/03, 12:41 »

Hi,

the ph pack / unpack just put  a binary (double in ths icase) into the byte stream. For whatever reason the bytes appear in reverse, at least on PC hardware. So I actually read 8 bytes, swap them, and then pass the result to php as a double ... and same thing the other way round

There is no spec for amf, just things that flash users have discovered

Musicman
Logged
Shalom Levytam
Server what's that
*
Posts: 10



View Profile Email
« Reply #33 on: 01/16/03, 17:59 »

Hello,

I am having some problems implementing amf on my local machine.  I have php installed and it works fine; however, when I run the test I get nothing.  

If I transfer the file to my webserver AMF is successful.  I am running the lastest version of apace and php for win32.

Thanks,

--SL
Logged
Musicman
Administrator
Systems Administrator
*****
Posts: 2685



View Profile WWW Email
« Reply #34 on: 01/16/03, 18:09 »

Hi,

in case your machine is reachable from the outside, I would like to trace the data - I suspect that php finds some "unix line endings" in the binary data and translates them  to "windows line endings"

Musicman
Logged
Shalom Levytam
Server what's that
*
Posts: 10



View Profile Email
« Reply #35 on: 01/16/03, 18:13 »

Hello,

My machine should be reachable.  If you give me an email address, I will send you my ip.

--SL
Logged
jolly
Server what's that
*
Posts: 2



View Profile Email
« Reply #36 on: 01/17/03, 04:16 »

Forgive me if I'm stating the obvious here, but is there any reason for us not doing it the Macromedia-way....
Code:

#include "NetServices.as"

NetServices.setDefaultGatewayURL("http://localhost/flashservices/gateway.php")
var myServer = NetServices.createGatewayConnection();

myService = myServer.getService("myService.php", this);

myService.myFunction();
function myFunction_Result(result){
      _root.display = result; // _root.display being a text box              

}


adding a tinsy bit to musicmans code...
Code:

function amfdata()
{...
   for($ni = 0 ; $ni < $lo ; $ni++)
   {   $ch = ord($d[$n++]);
      $this->fnargs[] = $this->parseitem($ch, $d, $n);
   }
}
//extra .... surely not the most elegant way to do this but anyway....
   $pathArray = explode("." , $this->fn);
   $this->method = array_pop($pathArray);
   $extension = array_pop($pathArray);
   $fileName = array_pop($pathArray);
   $this->service = $fileName . "." . $extension;
   $this->path = implode("/" , $pathArray);
         
//

return $this;



and then gateway.php would be...

Code:

<?
   include "amfdata.php";

   $request = new amfdata();
   include $request->service;
   $func = $request->method;
   $request->sendresult($func());
?>


then all our services can be separate php files eg "flashservices/myService.php" with separate methods in them for the service...

Code:

<?
function myFunction(){
   return "boo";
}
?>


seems to be the easiest way to organize services with php....the only thing is, stick..
Code:

#include "NetDebug.as"

...into the flash file and it seems to spit out something different...hmmmm

Jolly..

Logged
justin
Server what's that
*
Posts: 6



View Profile Email
« Reply #37 on: 01/17/03, 10:48 »

Just relax on that thought for a few hours.  I've spent quite a few hours restructuring musicman's code to do so.  I also broke the code up into classes gateway, input, deserializer, executive, output, and serializer. I also fixed a few issues with the ordering of header bytes and identified what of a few of the ignored bytes stood for.

Right now I'm working on adding recordset support because that is where the beauty of the framework lies.  Once that's done I'll send an updated version.  Then I will try to add the support for error handling and throwing an onStatus flag back to the client, but this takes a while because you have to learn as you go.


-- BTW, if someone is interested in looking at what I've got and help debugging and maybe a little coding please let me know.
« Last Edit: 01/17/03, 10:53 by justin » Logged
jolly
Server what's that
*
Posts: 2



View Profile Email
« Reply #38 on: 01/17/03, 11:20 »

Hey there Justin...

I'd be interested in helping...if I can that is...

Gimme a shout.. jollycowman@hotmail.com

jolly..
Logged
ryu
Guest


Email
« Reply #39 on: 01/18/03, 13:58 »

"amfdata.php" was used in two environments.
Flash-db's sample was used.

Turbo Linux : result is 23.45

MacOSX      : result is 4.66726146201902e-62

Please teach me how to improve this difference. ???

PowerMac G4 AGP 350MHz
MacOS X 10.1.5
PHP 4.3.0
Logged
Musicman
Administrator
Systems Administrator
*****
Posts: 2685



View Profile WWW Email
« Reply #40 on: 01/18/03, 15:33 »

Hi,

when I was working on the code, I was a bit surprised that double is stored just with all bytes swapped - as compared to the way php does it on the pc platform and swf files do it.
So there are two instances of byte swapping - one when reading the incoming request and one when sending data to the movie. Could you try whether skipping the inversion would do the proper thing.

Musicman
Logged
ryu
Guest


Email
« Reply #41 on: 01/19/03, 13:46 »

Hi, Musicman.

--------------------------------------------------
function getnumber($d, &$n)
{   $ibf = "";
   //for($nc = 7 ; $nc >= 0 ; $nc--)
   for($nc = 0 ; $nc <= 7 ; $nc++)
      $ibf .= $d[$n+$nc];
   $n += 8;
   $zz = unpack("dflt", $ibf);
   return $zz['flt'];
}

function sendnum($val)
{   $b = pack("d", $val);
   $r = "";
   //for($n = 7 ; $n >= 0 ; $n--)
   for($n = 0 ; $n <= 7 ; $n++)
      $r .= $b[$n];
   return $r;
}

--------------------------------------------------
It solved by this correction.
This looks like the difference in the platform of PPC and Intel.

These contents of correction are not what I created. Tongue

Please also add this correction.
Logged
AK
Seasoned Programmer
***
Posts: 103



View Profile Email
« Reply #42 on: 01/20/03, 16:14 »

Thanks ya'all, especially Musicman for such a brilliant effort while doing a huge favor to the open source community. I can see that Ryu has got it to work on Mac OS X, although I am still difficulties as I am unable to get any response back from the server, Here's my code:

------------------------------------------------

var nc = new NetConnection();
nc.connect("amfclient.php");
var reply = {};
reply.onResult = function(result){
trace("the result is"+result[0]);

};

data1="test";
data1="test2";
nc.call('script1',reply,data1,data2);

----------------------------------------------------


and PHP

------------------------------------------------------

<?

include "amfdata.php";
$request = new amfdata();

switch($request->fn)

{

  case 'script1':
 
  $sample = array("newTest1"=>"multiTest1","newTest2"=>"someValue");
  $data = array(0=>23.45,1=>5.3,"test"=>"AbdullahRemote","multiArray"=>$Sample);
 
  $request->sendresult($data);
 
 
}  



?>

--------------------------------------------------------------

Can anyone kindly upload some source files, I would really like to try them on my server. I am sure the problem is minor, but I can't seem to figure out why it isn't working on my server. Many thanks in advance.

-AK
Logged
Klaasjan Tukker
Server what's that
*
Posts: 9



View Profile WWW
« Reply #43 on: 01/20/03, 16:21 »

AK, Can you verify that the call is actually is being made. For example do you see a entry in you access-log of you webserver?

I can imagine you forgot to include the remoting libary:

#include "NetServices.as"

and then:

var nc = new NetConnection();

......

-- Klaasjan
Logged
Klaasjan Tukker
Server what's that
*
Posts: 9



View Profile WWW
« Reply #44 on: 01/20/03, 16:45 »

I've been playing around a little bit with the amf-class.

Consider the following Actionscript example:

#include "NetServices.as"

conn = NetServices.setDefaultGatewayURL("http://localhost/gateway.php");
conn = NetServices.createGatewayConnection();
service = conn.getService("myPackage");   

var reply = new Object();
reply.onResult = function(result) {
       trace('default return function handler');      
};

service.myFunction(reply,arg1,arg2);

This is very nice piece of readable code. Actually it is the classbook Flash remoting example. In my oppinion, the amf-class can be extended to make this possible.

The PHP-value on the server $rqst->fn returns in this case "myPackage.myFunction"

It would be very need to write some kind of package / function discovery mechanism and separate separate functionalities on the server. It gives more readable call on the client-side.

I like to hear some oppinions on this.
Logged
Pages: 1 2 [3] 4 5 6 Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!