Remoting - PHP Server, Flash Client

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Remoting - PHP Server, Flash Client

Steve Wilson-2
Hello,

Would somebody please be kind enough to provide a newbie with an up to date remoting example, preferably showing a connection between a PHP server and a Flash client. I have found numerous examples of haXe remoting on the internet but none of them seem to work, I think the remoting api must have changed and the examples are calling classes or members that are no longer present as the compiler just complains about them.

Also I'm a little unclear about the capabilites of remoting and I hope someone can provide some clarity for me, can the client dynamically create new instances of objects on the server or does the server create a fixed number of objects and it is only that number that is available to the client?

Thanks.

Steve


__________ Information from ESET NOD32 Antivirus, version of virus signature database 5312 (20100726) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
This email and attachments may contain confidential and/or privileged information and is intended only for the person or entity to which it is addressed.  If you are not the intended recipient of this email and attachments you should not disseminate, distribute or copy  them. If you believe you have received the email and attachments in error please contact the sender immediately and delete the contents from your system .
Any views or opinions are solely those of the author and do not necessarily represent those of Cambridge Electronic Industries Ltd.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Remoting - PHP Server, Flash Client

go2ghana
  Am 26.07.2010 11:00, schrieb Steve Wilson:
> Hello,
>
> Would somebody please be kind enough to provide a newbie with an up to
> date remoting example, preferably showing a connection between a PHP
> server and a Flash client. I have found numerous examples of haXe
> remoting on the internet but none of them seem to work, I think the
> remoting api must have changed and the examples are calling classes or
> members that are no longer present as the compiler just complains
> about them.
Hi Steve,
are you talking about a real php server process running on the host?
Since the usual Apache based php request would have to use some way to
store persistent data and implemented differently
than a continuously running server.

Cordially,
Axel

>
> Also I'm a little unclear about the capabilites of remoting and I hope
> someone can provide some clarity for me, can the client dynamically
> create new instances of objects on the server or does the server
> create a fixed number of objects and it is only that number that is
> available to the client?
>
> Thanks.
>
> Steve
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 5312 (20100726) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
> This email and attachments may contain confidential and/or privileged
> information and is intended only for the person or entity to which it
> is addressed.  If you are not the intended recipient of this email and
> attachments you should not disseminate, distribute or copy  them. If
> you believe you have received the email and attachments in error
> please contact the sender immediately and delete the contents from
> your system .
> Any views or opinions are solely those of the author and do not
> necessarily represent those of Cambridge Electronic Industries Ltd.


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Remoting - PHP Server, Flash Client

Steve Wilson-2
Thanks for your reply Axel,

"are you talking about a real php server process running on the host?"
Let me explain what I was hoping to achieve:

I have no previous experience of web development and having spent a little time reading about PHP, HTML, CSS and JavaScript I decided I didn't fancy that very much. I was hoping to use haXe to make web development more like desktop development with Flash / AsWing client side, PHP (as that's what most hosts offer) server side and using haxe.remoting to bridge the gap. I don't want to use the PHP to create and format web pages but instead to query and/or update databases using object(s) which would be made available to the client by remoting.

Is this possible?

Thanks and regards.

Steve

~

Axel Huizinga wrote:
 Am 26.07.2010 11:00, schrieb Steve Wilson:
Hello,

Would somebody please be kind enough to provide a newbie with an up to date remoting example, preferably showing a connection between a PHP server and a Flash client. I have found numerous examples of haXe remoting on the internet but none of them seem to work, I think the remoting api must have changed and the examples are calling classes or members that are no longer present as the compiler just complains about them.
Hi Steve,
are you talking about a real php server process running on the host?
Since the usual Apache based php request would have to use some way to store persistent data and implemented differently
than a continuously running server.

Cordially,
Axel

Also I'm a little unclear about the capabilites of remoting and I hope someone can provide some clarity for me, can the client dynamically create new instances of objects on the server or does the server create a fixed number of objects and it is only that number that is available to the client?

Thanks.

Steve


__________ Information from ESET NOD32 Antivirus, version of virus signature database 5312 (20100726) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
This email and attachments may contain confidential and/or privileged information and is intended only for the person or entity to which it is addressed.  If you are not the intended recipient of this email and attachments you should not disseminate, distribute or copy  them. If you believe you have received the email and attachments in error please contact the sender immediately and delete the contents from your system .
Any views or opinions are solely those of the author and do not necessarily represent those of Cambridge Electronic Industries Ltd.





__________ Information from ESET NOD32 Antivirus, version of virus signature database 5313 (20100726) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
This email and attachments may contain confidential and/or privileged information and is intended only for the person or entity to which it is addressed.  If you are not the intended recipient of this email and attachments you should not disseminate, distribute or copy  them. If you believe you have received the email and attachments in error please contact the sender immediately and delete the contents from your system .
Any views or opinions are solely those of the author and do not necessarily represent those of Cambridge Electronic Industries Ltd.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Remoting - PHP Server, Flash Client

Benjamin Dasnois
Hello,

If I correctly get what you want: PHP scripts that do not output a page but perform queries on request (that's how most web-services are done) ; Flash communicating with PHP : well I guess you could make some HTTP requests from Flash or use haXe remoting.

So, short answer is yes. 

Regards,


On Mon, Jul 26, 2010 at 1:27 PM, Steve Wilson <[hidden email]> wrote:
Thanks for your reply Axel,


"are you talking about a real php server process running on the host?"
Let me explain what I was hoping to achieve:

I have no previous experience of web development and having spent a little time reading about PHP, HTML, CSS and JavaScript I decided I didn't fancy that very much. I was hoping to use haXe to make web development more like desktop development with Flash / AsWing client side, PHP (as that's what most hosts offer) server side and using haxe.remoting to bridge the gap. I don't want to use the PHP to create and format web pages but instead to query and/or update databases using object(s) which would be made available to the client by remoting.

Is this possible?

Thanks and regards.

Steve

~


Axel Huizinga wrote:
 Am 26.07.2010 11:00, schrieb Steve Wilson:
Hello,

Would somebody please be kind enough to provide a newbie with an up to date remoting example, preferably showing a connection between a PHP server and a Flash client. I have found numerous examples of haXe remoting on the internet but none of them seem to work, I think the remoting api must have changed and the examples are calling classes or members that are no longer present as the compiler just complains about them.
Hi Steve,
are you talking about a real php server process running on the host?
Since the usual Apache based php request would have to use some way to store persistent data and implemented differently
than a continuously running server.

Cordially,
Axel

Also I'm a little unclear about the capabilites of remoting and I hope someone can provide some clarity for me, can the client dynamically create new instances of objects on the server or does the server create a fixed number of objects and it is only that number that is available to the client?

Thanks.

Steve


__________ Information from ESET NOD32 Antivirus, version of virus signature database 5312 (20100726) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
This email and attachments may contain confidential and/or privileged information and is intended only for the person or entity to which it is addressed.  If you are not the intended recipient of this email and attachments you should not disseminate, distribute or copy  them. If you believe you have received the email and attachments in error please contact the sender immediately and delete the contents from your system .
Any views or opinions are solely those of the author and do not necessarily represent those of Cambridge Electronic Industries Ltd.





__________ Information from ESET NOD32 Antivirus, version of virus signature database 5313 (20100726) __________


The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
This email and attachments may contain confidential and/or privileged information and is intended only for the person or entity to which it is addressed.  If you are not the intended recipient of this email and attachments you should not disseminate, distribute or copy  them. If you believe you have received the email and attachments in error please contact the sender immediately and delete the contents from your system .
Any views or opinions are solely those of the author and do not necessarily represent those of Cambridge Electronic Industries Ltd.

--
haXe - an open source web programming language
http://haxe.org



--
DASNOIS Benjamin
http://www.benjamindasnois.com

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Remoting - PHP Server, Flash Client

MarcWeber
In reply to this post by Steve Wilson-2
Excerpts from Steve Wilson's message of Mon Jul 26 11:00:48 +0200 2010:

> Hello,
>
> Would somebody please be kind enough to provide a newbie with an up to
> date remoting example, preferably showing a connection between a PHP
> server and a Flash client. I have found numerous examples of haXe
> remoting on the internet but none of them seem to work, I think the
> remoting api must have changed and the examples are calling classes or
> members that are no longer present as the compiler just complains about
> them.
>
> Also I'm a little unclear about the capabilites of remoting and I hope
> someone can provide some clarity for me, can the client dynamically
> create new instances of objects on the server or does the server create
> a fixed number of objects and it is only that number that is available
> to the client?
>
> Thanks.
>
> Steve

Hi Steve,

think about it in a different way: You define "interfaces" You expose
them to clients by enabling remoting. Then you can call the interfaces
from client. I"m not sure which objects you're talking about.
Of course you can add a function "create objects on server" and call
that function. However eg using PHP its your task to ensure that they
are persistent. Eg you have to store them to a database or such -
because PHP always "stops" after the request has been servered.
So to keep state on server side you have to store it
- on filesystem
- in databases
- using session
- using cookies
- ...

Can you refer to one of those "not working examples" on haxe.org, so
that we can fix the code for everyone?

Marc Weber

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Remoting - PHP Server, Flash Client

go2ghana
In reply to this post by Steve Wilson-2
  Hi Steve - as you already could read on the list it's perfectly possible.

I use the Remoting Proxy approach since it gives you a strictly typed
Api to share between client and server.

See the simple example below:

Api.hx:

class Api     {
     //         // The static members are used to create an instance of
this class, and share it for remoting         //
     static var instance : Api;

     static function main()
     {
         instance = new Api();
       // create an incoming connection and give access to the
"instance" object
         var context = new haxe.remoting.Context();
         context.addObject("api",instance);
         haxe.remoting.HttpConnection.handleRequest(context);
     }

    //         // The rest of the members are available to
remoting         //

     private var loginOkay:Bool;
     private var username:String;

     public function new()         {
        #if php
        // php code goes goes here, I will usually check here that they
are logged in correctly
        #end
     }

     public function test(x : Int, y : Int) : Int
     {
         return x + y;
     }

}

--------------------------------------------------------
ApiClient.hx:
--------------------------------------------------------

import haxe.remoting.HttpAsyncConnection;

class ApiProxy extends haxe.remoting.AsyncProxy<Api> { }

class ApiClient
{
     static var url:String;
     static var cnx:HttpAsyncConnection;
     static var proxy:ApiProxy;

     static function main()
     {
         url = "index.php";
         cnx = HttpAsyncConnection.urlConnect(url);
         proxy =  new ApiProxy(cnx.api);
         proxy.test(3, 5, display);

     }
     static function display(result:Int)
     {
         trace ("The server calculated 3 + 5 to equal: " + result);
     }

}

---------------------------------------
Api.hxml:
---------------------------------------


-php www
-main Api

--next

-swf9 www/ApiClient.swf
-main ApiClient


----------------------------------------
put the files on DocumentRoot

compile with haXe Api.hxml


then you can goto localhost/www/ApiClient.swf to see it at work



Cordially,
Axel

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Remoting - PHP Server, Flash Client

Steve Wilson-2
Thank you very much for taking the time to demonstrate this for me Axel, I really appreciate your help.

Steve.


Axel Huizinga wrote:
 Hi Steve - as you already could read on the list it's perfectly possible.

I use the Remoting Proxy approach since it gives you a strictly typed Api to share between client and server.

See the simple example below:

Api.hx:

class Api     {
    //         // The static members are used to create an instance of this class, and share it for remoting         //
    static var instance : Api;

    static function main()
    {
        instance = new Api();
      // create an incoming connection and give access to the "instance" object
        var context = new haxe.remoting.Context();
        context.addObject("api",instance);
        haxe.remoting.HttpConnection.handleRequest(context);
    }

   //         // The rest of the members are available to remoting         //

    private var loginOkay:Bool;
    private var username:String;

    public function new()         {
       #if php
       // php code goes goes here, I will usually check here that they are logged in correctly
       #end
    }

    public function test(x : Int, y : Int) : Int
    {
        return x + y;
    }

}

--------------------------------------------------------
ApiClient.hx:
--------------------------------------------------------

import haxe.remoting.HttpAsyncConnection;

class ApiProxy extends haxe.remoting.AsyncProxy<Api> { }

class ApiClient
{
    static var url:String;
    static var cnx:HttpAsyncConnection;
    static var proxy:ApiProxy;

    static function main()
    {
        url = "index.php";
        cnx = HttpAsyncConnection.urlConnect(url);
        proxy =  new ApiProxy(cnx.api);
        proxy.test(3, 5, display);

    }
    static function display(result:Int)
    {
        trace ("The server calculated 3 + 5 to equal: " + result);
    }

}

---------------------------------------
Api.hxml:
---------------------------------------


-php www
-main Api

--next

-swf9 www/ApiClient.swf
-main ApiClient


----------------------------------------
put the files on DocumentRoot

compile with haXe Api.hxml


then you can goto localhost/www/ApiClient.swf to see it at work



Cordially,
Axel




__________ Information from ESET NOD32 Antivirus, version of virus signature database 5315 (20100726) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
This email and attachments may contain confidential and/or privileged information and is intended only for the person or entity to which it is addressed.  If you are not the intended recipient of this email and attachments you should not disseminate, distribute or copy  them. If you believe you have received the email and attachments in error please contact the sender immediately and delete the contents from your system .
Any views or opinions are solely those of the author and do not necessarily represent those of Cambridge Electronic Industries Ltd.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Remoting - PHP Server, Flash Client

Steve Wilson-2
In reply to this post by MarcWeber
Hello Marc,

Of course you can add a function "create objects on server" and call
that function. However eg using PHP its your task to ensure that they
are persistent. Eg you have to store them to a database or such -
because PHP always "stops" after the request has been servered.
So to keep state on server side you have to store it
- on filesystem
- in databases
- using session
- using cookies
- ...


So if I add a function that creates an object on the server will that object be destroyed the moment PHP has dealt with my initial request even though the connection remains?


Can you refer to one of those "not working examples" on haxe.org, so
that we can fix the code for everyone?

I purchased this book from Amazon: http://haxe.org/doc/book?lang=en
and downloaded the source code from the book here: http://haxe.org/file/Professional-haXe-and-Neko-code.zip

I think the API has changed since the book was written, for example if I try to compile this:


class Client {
  public static function main() {
    var calc = haxe.remoting.Connection.jsConnect("calc");
    try{
      trace(calc.sum.call([5,4]));
    } catch(e : Dynamic) {
      trace(Std.string(e));
    }
  }
}


the compilers says: 'haxe.remoting.#Connection has no field jsConnect'
and similarly with this:


class Client {
  public static function main() {
    haxe.Timer.delayed(function() {
      var cnx8 = haxe.remoting.Connection.flashConnect("flashmovie8");
      try {
        trace(cnx8.Calc.sum.call([5,4]));
      } catch(e : Dynamic) {
        trace(Std.string(e));
      }

      var cnx9 = haxe.remoting.Connection.flashConnect("flashmovie9");
      try {
        trace(cnx9.Calc.sum.call([5,4]));
      } catch(e : Dynamic) {
        trace(Std.string(e));
      }
    }, 200)();
  }
}


Thanks

Steve.

Marc Weber wrote:
Excerpts from Steve Wilson's message of Mon Jul 26 11:00:48 +0200 2010:
  
Hello,

Would somebody please be kind enough to provide a newbie with an up to 
date remoting example, preferably showing a connection between a PHP 
server and a Flash client. I have found numerous examples of haXe 
remoting on the internet but none of them seem to work, I think the 
remoting api must have changed and the examples are calling classes or 
members that are no longer present as the compiler just complains about 
them.

Also I'm a little unclear about the capabilites of remoting and I hope 
someone can provide some clarity for me, can the client dynamically 
create new instances of objects on the server or does the server create 
a fixed number of objects and it is only that number that is available 
to the client?

Thanks.

Steve
    

Hi Steve,

think about it in a different way: You define "interfaces" You expose
them to clients by enabling remoting. Then you can call the interfaces
from client. I"m not sure which objects you're talking about.
Of course you can add a function "create objects on server" and call
that function. However eg using PHP its your task to ensure that they
are persistent. Eg you have to store them to a database or such -
because PHP always "stops" after the request has been servered.
So to keep state on server side you have to store it
- on filesystem
- in databases
- using session
- using cookies
- ...

Can you refer to one of those "not working examples" on haxe.org, so
that we can fix the code for everyone?

Marc Weber

  



__________ Information from ESET NOD32 Antivirus, version of virus signature database 5315 (20100726) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
This email and attachments may contain confidential and/or privileged information and is intended only for the person or entity to which it is addressed.  If you are not the intended recipient of this email and attachments you should not disseminate, distribute or copy  them. If you believe you have received the email and attachments in error please contact the sender immediately and delete the contents from your system .
Any views or opinions are solely those of the author and do not necessarily represent those of Cambridge Electronic Industries Ltd.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Remoting - PHP Server, Flash Client

go2ghana
  Am 27.07.2010 10:41, schrieb Steve Wilson:

> Hello Marc,
> /
> Of course you can add a function "create objects on server" and call
> that function. However eg using PHP its your task to ensure that they
> are persistent. Eg you have to store them to a database or such -
> because PHP always "stops" after the request has been servered.
> So to keep state on server side you have to store it
> - on filesystem
> - in databases
> - using session
> - using cookies
> - .../
>
> So if I add a function that creates an object on the server will that
> object be destroyed the moment PHP has dealt with my initial request
> even though the connection remains?
>
>
Yes,
and it is also recommended to close the connection since reopening on
the next request is not expensive.
If you need persistence you have to store data in the db or on file or
memeory to share between requests.

Axel

> /Can you refer to one of those "not working examples" on haxe.org, so
> that we can fix the code for everyone?
>
> /I purchased this book from Amazon: http://haxe.org/doc/book?lang=en
> and downloaded the source code from the book here:
> http://haxe.org/file/Professional-haXe-and-Neko-code.zip
>
> I think the API has changed since the book was written, for example if
> I try to compile this:
>
> class Client {
>   public static function main() {
>     var calc = haxe.remoting.Connection.jsConnect("calc");
>     try{
>       trace(calc.sum.call([5,4]));
>     } catch(e : Dynamic) {
>       trace(Std.string(e));
>     }
>   }
> }
>
> the compilers says: 'haxe.remoting.#Connection has no field jsConnect'
> and similarly with this:
>
> class Client {
>   public static function main() {
>     haxe.Timer.delayed(function() {
>       var cnx8 = haxe.remoting.Connection.flashConnect("flashmovie8");
>       try {
>         trace(cnx8.Calc.sum.call([5,4]));
>       } catch(e : Dynamic) {
>         trace(Std.string(e));
>       }
>
>       var cnx9 = haxe.remoting.Connection.flashConnect("flashmovie9");
>       try {
>         trace(cnx9.Calc.sum.call([5,4]));
>       } catch(e : Dynamic) {
>         trace(Std.string(e));
>       }
>     }, 200)();
>   }
> }
>
> Thanks
>
> Steve.
>
> Marc Weber wrote:
>> Excerpts from Steve Wilson's message of Mon Jul 26 11:00:48 +0200 2010:
>>    
>>> Hello,
>>>
>>> Would somebody please be kind enough to provide a newbie with an up to
>>> date remoting example, preferably showing a connection between a PHP
>>> server and a Flash client. I have found numerous examples of haXe
>>> remoting on the internet but none of them seem to work, I think the
>>> remoting api must have changed and the examples are calling classes or
>>> members that are no longer present as the compiler just complains about
>>> them.
>>>
>>> Also I'm a little unclear about the capabilites of remoting and I hope
>>> someone can provide some clarity for me, can the client dynamically
>>> create new instances of objects on the server or does the server create
>>> a fixed number of objects and it is only that number that is available
>>> to the client?
>>>
>>> Thanks.
>>>
>>> Steve
>>>      
>>
>> Hi Steve,
>>
>> think about it in a different way: You define "interfaces" You expose
>> them to clients by enabling remoting. Then you can call the interfaces
>> from client. I"m not sure which objects you're talking about.
>> Of course you can add a function "create objects on server" and call
>> that function. However eg using PHP its your task to ensure that they
>> are persistent. Eg you have to store them to a database or such -
>> because PHP always "stops" after the request has been servered.
>> So to keep state on server side you have to store it
>> - on filesystem
>> - in databases
>> - using session
>> - using cookies
>> - ...
>>
>> Can you refer to one of those "not working examples" on haxe.org, so
>> that we can fix the code for everyone?
>>
>> Marc Weber
>>
>>    
>
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 5315 (20100726) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
> This email and attachments may contain confidential and/or privileged
> information and is intended only for the person or entity to which it
> is addressed.  If you are not the intended recipient of this email and
> attachments you should not disseminate, distribute or copy  them. If
> you believe you have received the email and attachments in error
> please contact the sender immediately and delete the contents from
> your system .
> Any views or opinions are solely those of the author and do not
> necessarily represent those of Cambridge Electronic Industries Ltd.


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Remoting - PHP Server, Flash Client

MarcWeber
In reply to this post by Steve Wilson-2
Hi Steve,

PHP is stupid. It forgets everything after a connection finished.
I'd even say its good that way - because PHP programmers often don't
clean up - because PHP will forget everything anyway. Maybe being able
to be that lazy can even be considered cool :-P

If you started a persistent connection to PHP what would happen?
- PHP would time out after 90sec or such - you can switch that off
  though
- PHP could (in theory) store the objects in memory. I don't know
  whether PHP can continue reading data which is sent later. Probably
  only GET/POST is supported. So sending data second time using the same
  connection is hard if possible at all.

  If it was possible it would make no sense because: If another browser
  connected to the (let's say Apache) server the server would start a
  second PHP server thread. Both threads can't communicate.
  So the second thread can't get the stored data by the first one
  - unless you start storing stuff in a database etc.

So thinking about a persistent connection targeting PHP doesn't make
sense. (I may be mistaken - I'm not a PHP guru..). The only thing PHP
can share are database connections for speed reasons.

> So if I add a function that creates an object on the server will that
> object be destroyed the moment PHP has dealt with my initial request
> even though the connection remains?
If the connection remains the PHP thread won't stop - so your ojbect
will not be destroyed. However I doubt that you can send additional
data..

> /I purchased this book from Amazon: http://haxe.org/doc/book?lang=en
> and downloaded the source code from the book here:
> http://haxe.org/file/Professional-haXe-and-Neko-code.zip
>
> I think the API has changed since the book was written, for example if I
> try to compile this:
>
> class Client {
>   public static function main() {
>     var calc = haxe.remoting.Connection.jsConnect("calc");
>     try{
>       trace(calc.sum.call([5,4]));
>     } catch(e : Dynamic) {
>       trace(Std.string(e));
>     }
>   }
> }
>
> the compilers says: 'haxe.remoting.#Connection has no field jsConnect'
> and similarly with this:
>
> class Client {
>   public static function main() {
>     haxe.Timer.delayed(function() {
>       var cnx8 = haxe.remoting.Connection.flashConnect("flashmovie8");
>       try {
>         trace(cnx8.Calc.sum.call([5,4]));
>       } catch(e : Dynamic) {
>         trace(Std.string(e));
>       }
>
>       var cnx9 = haxe.remoting.Connection.flashConnect("flashmovie9");
>       try {
>         trace(cnx9.Calc.sum.call([5,4]));
>       } catch(e : Dynamic) {
>         trace(Std.string(e));
>       }
>     }, 200)();
>   }
> }
>
> Thanks
>
> Steve.

Yes, the examples may be outdated. In general the haxe.org page is very
nice. If the examples don't work we should try to put working exapmles
online. Note: The HaXe page search is bad. use google
  "site:hax.org keyword" search  feature instead.

There are several pages:

  http://haxe.org/doc/remoting/0_introduction
  http://haxe.org/doc/remoting/flash_js
  http://haxe.org/doc/remoting/client_server
  http://haxe.org/doc/flash/chat

The key difference is Async vs non async communication. non async blocks
but is easier to write because you don't have to write callback
functions.

Also note that the Neko server *can* keep state. That's how the chat
example works. You can't recode it that way in PHP. You would have to
store messages in DB and start polling or such :-(

About jsConnect: Maybe you're targeting the wrong language?

If you can't get one of those examples running after copy & paste let me
help you update the wiki content.

Yours
Marc Weber

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Remoting - PHP Server, Flash Client

Ron Wheeler
  The API for remoting changed shortly after the book came out.
The general philosophy is true but the book's code is wrong.

Follow the examples on the HaXe site.

We used Neko on the server to persist our data in a MySQL database.
In this way you only have 1 language to program in (HaXe) and you can
actually share the message classes.
Unfortunately, that is all you share but it works really well and is
very robust on both sides of the transaction.

You can probably take the example off the HaXe site and just change the
data to get your application saving data on the server.

Ron

On 27/07/2010 9:17 AM, Marc Weber wrote:

> Hi Steve,
>
> PHP is stupid. It forgets everything after a connection finished.
> I'd even say its good that way - because PHP programmers often don't
> clean up - because PHP will forget everything anyway. Maybe being able
> to be that lazy can even be considered cool :-P
>
> If you started a persistent connection to PHP what would happen?
> - PHP would time out after 90sec or such - you can switch that off
>    though
> - PHP could (in theory) store the objects in memory. I don't know
>    whether PHP can continue reading data which is sent later. Probably
>    only GET/POST is supported. So sending data second time using the same
>    connection is hard if possible at all.
>
>    If it was possible it would make no sense because: If another browser
>    connected to the (let's say Apache) server the server would start a
>    second PHP server thread. Both threads can't communicate.
>    So the second thread can't get the stored data by the first one
>    - unless you start storing stuff in a database etc.
>
> So thinking about a persistent connection targeting PHP doesn't make
> sense. (I may be mistaken - I'm not a PHP guru..). The only thing PHP
> can share are database connections for speed reasons.
>
>> So if I add a function that creates an object on the server will that
>> object be destroyed the moment PHP has dealt with my initial request
>> even though the connection remains?
> If the connection remains the PHP thread won't stop - so your ojbect
> will not be destroyed. However I doubt that you can send additional
> data..
>
>> /I purchased this book from Amazon: http://haxe.org/doc/book?lang=en
>> and downloaded the source code from the book here:
>> http://haxe.org/file/Professional-haXe-and-Neko-code.zip
>>
>> I think the API has changed since the book was written, for example if I
>> try to compile this:
>>
>> class Client {
>>    public static function main() {
>>      var calc = haxe.remoting.Connection.jsConnect("calc");
>>      try{
>>        trace(calc.sum.call([5,4]));
>>      } catch(e : Dynamic) {
>>        trace(Std.string(e));
>>      }
>>    }
>> }
>>
>> the compilers says: 'haxe.remoting.#Connection has no field jsConnect'
>> and similarly with this:
>>
>> class Client {
>>    public static function main() {
>>      haxe.Timer.delayed(function() {
>>        var cnx8 = haxe.remoting.Connection.flashConnect("flashmovie8");
>>        try {
>>          trace(cnx8.Calc.sum.call([5,4]));
>>        } catch(e : Dynamic) {
>>          trace(Std.string(e));
>>        }
>>
>>        var cnx9 = haxe.remoting.Connection.flashConnect("flashmovie9");
>>        try {
>>          trace(cnx9.Calc.sum.call([5,4]));
>>        } catch(e : Dynamic) {
>>          trace(Std.string(e));
>>        }
>>      }, 200)();
>>    }
>> }
>>
>> Thanks
>>
>> Steve.
> Yes, the examples may be outdated. In general the haxe.org page is very
> nice. If the examples don't work we should try to put working exapmles
> online. Note: The HaXe page search is bad. use google
>    "site:hax.org keyword" search  feature instead.
>
> There are several pages:
>
>    http://haxe.org/doc/remoting/0_introduction
>    http://haxe.org/doc/remoting/flash_js
>    http://haxe.org/doc/remoting/client_server
>    http://haxe.org/doc/flash/chat
>
> The key difference is Async vs non async communication. non async blocks
> but is easier to write because you don't have to write callback
> functions.
>
> Also note that the Neko server *can* keep state. That's how the chat
> example works. You can't recode it that way in PHP. You would have to
> store messages in DB and start polling or such :-(
>
> About jsConnect: Maybe you're targeting the wrong language?
>
> If you can't get one of those examples running after copy&  paste let me
> help you update the wiki content.
>
> Yours
> Marc Weber
>


--
haXe - an open source web programming language
http://haxe.org