haxe, node.js and remoting

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

haxe, node.js and remoting

blackdog

I've just posted a blog entry on how to do haXe remoting with Node.js

http://cloudshift.cl/post/11224349570/haxenoderemotes

bd

--
Simplicity is the ultimate sophistication. ~ Leonardo da Vinci


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

Re: haxe, node.js and remoting

Dion Whitehead Amago
I've already implemented basically the same thing:

https://github.com/dionjwa/Hydrax/tree/master/src/haxe/remoting

Dion

On Sun, Oct 9, 2011 at 8:43 AM, blackdog <[hidden email]> wrote:

>
> I've just posted a blog entry on how to do haXe remoting with Node.js
>
> http://cloudshift.cl/post/11224349570/haxenoderemotes
>
> bd
>
> --
> Simplicity is the ultimate sophistication. ~ Leonardo da Vinci
>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

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

Re: haxe, node.js and remoting

Bruno Garcia-2
Thanks for the article!

I ended up writing something similar for my project as well :) Although
without macro type safety yet:
https://github.com/aduros/flambe/tree/master/src/flambe/server

I found it was useful to have a way to propagate uncaught exceptions on
the server back to the client, so that server errors don't leave the
connection hanging, and so the user can at least be shown an error
screen saying "something went wrong, try reloading".

So, NodeRelay was born. Rather than the last argument in a remoting
function being T->Void, it's a NodeRelay<T>. You can return a result by
calling relay.success(x) or fail with relay.error(y). Relays can be
chained together for asynchronous calls with full error handling.
Remoting on the server side looks something like this:

// A remoting handler
function addScore (playerId :Int, score :Int, relay :NodeRelay<Int>)
{
     // chain() creates a new relay and passes it to loadPlayer. If
loadPlayer errors out, the error
     // will be chained back to the original relay (and back to the client)
     myLib.loadPlayer(playerId, relay.chain(function (player) {
         if (validatePlayer(player)) {
             throw "Invalid state!"; // Uncaught exceptions are shipped
back to the client
         }
         // Many node libraries expect callbacks in the form of function
(error, result), where you need
         // to tediously check that error != null before processing the
result. nodeCallback wraps that for you
         nodeLib.doAsyncAddition(player.score, score,
relay.nodeCallback(function (sum) {
             relay.success(sum);
         }));
     }));
}

Bruno

On 10/09/2011 10:01 AM, Dion Whitehead Amago wrote:

> I've already implemented basically the same thing:
>
> https://github.com/dionjwa/Hydrax/tree/master/src/haxe/remoting
>
> Dion
>
> On Sun, Oct 9, 2011 at 8:43 AM, blackdog<[hidden email]>  wrote:
>> I've just posted a blog entry on how to do haXe remoting with Node.js
>>
>> http://cloudshift.cl/post/11224349570/haxenoderemotes
>>
>> bd
>>
>> --
>> Simplicity is the ultimate sophistication. ~ Leonardo da Vinci
>>
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org

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