remoting proxy callback error

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

remoting proxy callback error

go2ghana
Hi,
trying to use a callback in a js client / php server gives me a runtime
error:

Uncaught Cannot serialize function

Called from haxe.Serializer::serialize
Called from haxe.Serializer::serialize
Called from haxe.remoting.HttpAsyncConnection::call
Called form Async_Server::say
...

my code:

class Server{

     public function new(){}

     static function main() {
         var instance = new Server();
         var context = new haxe.remoting.Context();
         context.addObject("api", instance);
         haxe.remoting.HttpConnection.handleRequest(context);
     }

     public function say( text : String  , cb:String->Void) :Bool{

         cb(text);
         return true;
     }
}

---

import haxe.remoting.HttpAsyncConnection;

class ServerProxy extends haxe.remoting.AsyncProxy<Server> {
}

class Client{

     static var proxy : ServerProxy;

     static function cb(d)
     {
         trace(d);
     }

     static var c : Client;

     static function main() {
         var cnx = HttpAsyncConnection.urlConnect('index.php');
         cnx.setErrorHandler(processServerSideError);
         proxy = new ServerProxy(cnx.api);
         proxy.say('hi', cb);
     }

     static function processServerSideError(error:Dynamic):Void
     {
       trace (error);
     }

}
---


-main Server
-php D:\www\devel\js
--next

-debug
-main Client
-js  D:\www\devel\js\client.js

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

Re: remoting proxy callback error

Nicolas Cannasse
Le 09/11/2011 23:02, Axel Huizinga a écrit :
> Hi,
> trying to use a callback in a js client / php server gives me a runtime
> error:
>
> Uncaught Cannot serialize function

Your "say" function should just return text.

Best,
Nicolas

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

Re: remoting proxy callback error

go2ghana
Am 10.11.2011 06:21, schrieb Nicolas Cannasse:
> Le 09/11/2011 23:02, Axel Huizinga a écrit :
>> Hi,
>> trying to use a callback in a js client / php server gives me a runtime
>> error:
>>
>> Uncaught Cannot serialize function
>
> Your "say" function should just return text.
hmm ... don't get why this is required - anyway tried and changed to:

     public function say( text : String  , cb:String->Void) :String{

         cb(text);
         return text;
     }

but still get the same error?
>
> Best,
> Nicolas
>


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

Re: remoting proxy callback error

Nicolas Cannasse
Le 10/11/2011 07:20, Axel Huizinga a écrit :

> Am 10.11.2011 06:21, schrieb Nicolas Cannasse:
>> Le 09/11/2011 23:02, Axel Huizinga a écrit :
>>> Hi,
>>> trying to use a callback in a js client / php server gives me a runtime
>>> error:
>>>
>>> Uncaught Cannot serialize function
>>
>> Your "say" function should just return text.
> hmm ... don't get why this is required - anyway tried and changed to:
>
> public function say( text : String , cb:String->Void) :String{
>
> cb(text);
> return text;
> }
>
> but still get the same error?

I meant :

function say( text : String ) {
    return text;
}

You don't have to use a callback on the server-side, it's only the
client which is using an async proxy.

Best,
Nicolas

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

Re: remoting proxy callback error

go2ghana
Am 10.11.2011 07:25, schrieb Nicolas Cannasse:

> Le 10/11/2011 07:20, Axel Huizinga a écrit :
>> Am 10.11.2011 06:21, schrieb Nicolas Cannasse:
>>> Le 09/11/2011 23:02, Axel Huizinga a écrit :
>>>> Hi,
>>>> trying to use a callback in a js client / php server gives me a
>>>> runtime
>>>> error:
>>>>
>>>> Uncaught Cannot serialize function
>>>
>>> Your "say" function should just return text.
>> hmm ... don't get why this is required - anyway tried and changed to:
>>
>> public function say( text : String , cb:String->Void) :String{
>>
>> cb(text);
>> return text;
>> }
>>
>> but still get the same error?
>
> I meant :
>
> function say( text : String ) {
>    return text;
> }
Thanks - this works well.
Does it mean that we can only pass String types in AsyncProxy communication?
>
> You don't have to use a callback on the server-side, it's only the
> client which is using an async proxy.
>
> Best,
> Nicolas
>


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