-
Notifications
You must be signed in to change notification settings - Fork 0
/
haxe_intro.html
176 lines (139 loc) · 7.78 KB
/
haxe_intro.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta name="keywords" content="Yaws"/>
<title>Yaws</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" type="text/css" href="stil.css"/>
<link rel="shortcut icon" href="/icons/yaws_y.gif" type="image/x-icon"/>
</head>
<body>
<div class="logo">
<img src="icons/yaws_head.gif" width="600" alt="YAWS"/>
</div>
<div id="sidebar">
<h4> Yaws </h4>
<div class=""> <a href="index.html" id="index" >Top Page</a> </div>
<div class=""> <a href="configuration.html" id="configuration">Build Config and Run</a></div>
<div class=""> <a href="dynamic.html" id="dynamic" >Dynamic Content</a> </div>
<div class=""> <a href="https://github.com/erlyaws/yaws/releases/" id="download">Download </a> </div>
<div class=""> <a href="contact.html" id="contact">Contact </a> </div>
<div class=""> <a href="doc.html" id="doc">Documentation</a> </div>
<div class=""> <a href="articles.html" id="resources">Articles</a> </div>
<h4> Examples </h4>
<div class=""> <a href="/json_intro.html">AJAX/JSON RPC</a></div>
<div class=""> <a href="/appmods.html">Appmods</a> </div>
<div class=""> <a href="/arg.html">Arg</a> </div>
<div class=""> <a href="/privbind.html">Binding to Privileged Ports</a></div>
<div class=""> <a href="/bindings.html">Bindings</a> </div>
<div class=""> <a href="/cgi.html">CGI</a></div>
<div class=""> <a href="/session.html">Cookie Sessions</a> </div>
<div class=""> <a href="/cookies.html">Cookies</a> </div>
<div class=""> <a href="/dynamic.html">Dynamic Content</a> </div>
<div class=""> <a href="/embed.html">Embedding Yaws</a></div>
<div class=""> <a href="/upload0.html">File Upload</a> </div>
<div class=""> <a href="/form.html">Forms</a> </div>
<div class="choosen"> <a href="/haxe_intro.html">haXe Remoting</a></div>
<div class=""> <a href="/pcookie.html">Persistent Cookies</a> </div>
<div class=""> <a href="/query.html">Query Part of URL</a></div>
<div class=""> <a href="/rebar_release.html">Rebar Releases</a></div>
<div class=""> <a href="/redirect.html">Redirect</a> </div>
<div class=""> <a href="/server_sent_events.html">Server-Sent Events</a> </div>
<div class=""> <a href="/ssi.html">Server Side Includes</a> </div>
<div class=""> <a href="/simple.html">Simple</a> </div>
<div class=""> <a href="/soap_intro.html">SOAP with Yaws</a></div>
<div class=""> <a href="/stream.html">Streaming Data</a> </div>
<div class=""> <a href="/websockets.html">Web Sockets</a> </div>
<a href="/shoppingcart/index.html">Tiny Shopping Cart</a>
<div class=""> <a href="/yapp_intro.html">Yaws Applications (yapps)</a></div>
<div class=""> <a href="/logger_mod.html">Write Your Own Logger</a></div>
<h4> Misc </h4>
<div class=""> <a href="/internals.html">Internals</a> </div>
</div>
<div id="entry">
<h1>haXe remoting</h1>
<p>The yaws_rpc module has a haXe remoting adapter that enables Yaws to respond to respond to RPC requests from a client written in <a href="https://www.haxe.org">haXe</a>. haXe is a versatile open source language that compiles to Flash, Javascript and NekoVM. For more information on haXe, visit <a href="https://www.haxe.org/intro">www.haxe.org/intro</a>.</p>
<p>Implementing the server side of a haXe remoting interaction in Yaws is very similar to the one described in the <a href="json_intro.html">Ajax/JSON RPC</a> page. Most of the action takes place behind the scenes inside the the yaws_rpc module. The same types (array, struct, number and string) work for haXe remoting as for JSON RPC. There are just a few new things to keep in mind when using haXe remoting: </p>
<ol>
<li>
<p>Class objects and enums work with standard haXe remoting, but are not supported in Yaws. You should therefore rely on anonymous objects and signatures when designing your haXe remoting calls.</p></li>
<li>
<p>A Yaws RPC handler can "throw an exception" by returning {exception, Obj}, where Obj is any valid haXe remoting value.</p></li>
<li>
<p>haXe remoting has a few extra values, expressed by the atoms 'infinity', 'neg_infinity' and 'nan', corresponding to infinity, negative infinity and 'not a number.'</p></li></ol>
<p>Following is an example demonstrating the use of haXe remoting in yaws. The first code segment is the haXe client code, which invokes the 'echo' method in haxe_sample.yaws and displays the result:</p>
<div class="box">
<pre>// To try this sample out using haXe and neko,
// save this file as Application.hx and run the following to compile it:
// haxe Application -neko Application.n -main Application.hx
// and the following to execute it:
// neko Application.n
class Application {
public static function main():Void {
var URL = "http://localhost:8000/haxe_sample.yaws";
var cnx = haxe.remoting.HttpAsyncConnection.urlConnect(URL);
cnx.setErrorHandler( function(err) {
trace("Exception : " + Std.string(err));
} );
var a = {a:"foo", b:"bar", c:[1,2,3]};
var b = "hello, Erlang!";
cnx.echo.call([a, b], display);
cnx.failure.call([a, b], display);
}
static function display(v) {
trace(v);
}
}
</pre></div>
<p>On the server side, we have the file haxe_sample.yaws with the following code: </p>
<div class="box">
<pre><erl module=haxe_sample>
-export([respond/2]).
out(A) ->
A1 = A#arg{state = {new_state, "alive and kicking"}},
yaws_rpc:handler(A1, {haxe_sample, respond}).
respond(State, {call, failure, Value} = _Request) ->
{ false, { error, { struct, [ { message, "Failure" }, { code, 500 } ] } } };
respond(State, {call, echo, Value} = _Request) ->
{new_state, StateVal} = State,
{array, [First, Second]} = Value,
Response =
{response,
{struct, [
{you_sent_first, First},
{btw, "Hello haXe!"},
{also, {array, ["take", "this", 4, "array"]}},
{my_state_is, StateVal}
]
}},
{true, 0, null, Response}.
</erl>
</pre></div>
<p>The two important lines on the server side are:</p>
<ol>
<li>
<pre>yaws_rpc:handler(A1, {haxe_sample, respond}).</pre></li>
<li>
<pre>respond(State, {call, echo, Value} = _Request)</pre></li></ol>
<p>The first line tells Yaws to forward all RPC calls (this includes both haXe remoting and JSON RPC calls -- remember that the yaws_rpc module handles both RPC mechanisms transparently) to the "respond" function in the "haxe_sample" module. </p>
<p>The second line tells Yaws to invoke this 'respond' function when the client requests the method 'echo', while passing the new state variable as the first argument to 'respond'. You should duplicate this line for every RPC method you wish to implement, replacing 'echo' with the method's name.</p>
<p>yaws_rpc optionally handles sessions for both JSON RPC and haXe remoting. To use sessions, invoke yaws_rpc:handler_session as shown in the JSON RPC documentation page.</p>
<p>If the response is in the form of {exception, Obj}, where Obj is any valid haXe remoting type, then the haXe client will invoke the 'onError' handler, with Obj passed as the parameter.</p>
<p>As with JSON RPC, both request and response values can be composed of nested tuples of the form</p>
<div class="box">
<pre>{array, [Obj,...]}</pre></div>
<p>and/or </p>
<div class="box">
<pre>{struct, [{prop, Val}...]}</pre></div>
<p>Now go have fun! :)</p></div><div class="logo">
<img src="/icons/yaws_pb.gif" alt="pbyaws" />
</div>
<p>
<a href="https://validator.w3.org/check?uri=referer"><img
src="https://www.w3.org/Icons/valid-xhtml10"
alt="Valid XHTML 1.0!" height="31" width="88" /></a>
</p>
</body>
</html>