Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 43 lines (32 sloc) 1.29 kB
47e5a7c @klacke JSON ajax code from Gaspar Chilingarov, I added docs describing an ex…
authored
1 <erl module=sample_mod>
51f035b @klacke small bug fixes
authored
2 -compile(export_all).
47e5a7c @klacke JSON ajax code from Gaspar Chilingarov, I added docs describing an ex…
authored
3
7811247 @vinoski whitespace cleanup
vinoski authored
4 out(A) ->
5b34d48 @vinoski wrap SSL sockets in tuple
vinoski authored
5 Peer = case yaws_api:get_sslsocket(A#arg.clisock) of
6 {ok, SslSocket} ->
7 ssl:peername(SslSocket);
8 _ ->
0be3c7e @klacke untabified all of yaws
authored
9 inet:peername(A#arg.clisock)
10 end,
7811247 @vinoski whitespace cleanup
vinoski authored
11
47e5a7c @klacke JSON ajax code from Gaspar Chilingarov, I added docs describing an ex…
authored
12 {ok,{IP,_}} = Peer,
13 A2=A#arg{state = [{ip, IP}]},
51f035b @klacke small bug fixes
authored
14 yaws_rpc:handler_session(A2, {?MODULE, counter}).
47e5a7c @klacke JSON ajax code from Gaspar Chilingarov, I added docs describing an ex…
authored
15
16
17
7811247 @vinoski whitespace cleanup
vinoski authored
18 counter([{ip, IP}] = _State, {call, errortest, Value} = _Request, Session) ->
af707a9 Add example for JSON-RPC returning an error object
Paul Hampson authored
19 io:format("Request = ~p~n", [_Request]),
20 { false, { error, "Expected failure" } };
21
7811247 @vinoski whitespace cleanup
vinoski authored
22 counter([{ip, IP}] = _State, {call, test1, Value} = _Request, Session) ->
47e5a7c @klacke JSON ajax code from Gaspar Chilingarov, I added docs describing an ex…
authored
23 io:format("Request = ~p~n", [_Request]),
24 IPStr = io_lib:format("Client ip is ~p~n" , [ IP ]),
25 OldSession = io_lib:format("Request is: ~p~nOld session value "
0be3c7e @klacke untabified all of yaws
authored
26 "is ~p~n", [ _Request, Session ]),
47e5a7c @klacke JSON ajax code from Gaspar Chilingarov, I added docs describing an ex…
authored
27
28 case Session of
0be3c7e @klacke untabified all of yaws
authored
29 undefined -> % create new session
30 NewSession = 0;
31 10 -> % reset session after reaching 10
32 NewSession = undefined;
7811247 @vinoski whitespace cleanup
vinoski authored
33 N ->
0be3c7e @klacke untabified all of yaws
authored
34 NewSession = N + 1
47e5a7c @klacke JSON ajax code from Gaspar Chilingarov, I added docs describing an ex…
authored
35 end,
7811247 @vinoski whitespace cleanup
vinoski authored
36
47e5a7c @klacke JSON ajax code from Gaspar Chilingarov, I added docs describing an ex…
authored
37 NewVal = io_lib:format("New session value is ~p ~n", [ NewSession ]),
38 Str = lists:flatten([IPStr,OldSession,NewVal]),
39 {true, 0, NewSession, {response, Str }}.
40
41
42 </erl>
Something went wrong with that request. Please try again.