Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 40 lines (30 sloc) 1.03 kB
d7ebc3c @KirinDave Initial commit.
KirinDave authored
1 <erl module=sample_mod>
2 -compile(export_all).
3
4 out(A) ->
5 Peer = if
6 tuple(A#arg.clisock),
7 element(1, A#arg.clisock) == sslsocket ->
8 ssl:peername(A#arg.clisock);
9 true ->
10 inet:peername(A#arg.clisock)
11 end,
12
13 {ok,{IP,_}} = Peer,
14 A2=A#arg{state = [{ip, IP}]},
15 yaws_rpc:handler_session(A2, {?MODULE, counter}).
16
17
18
19 counter([{ip, IP}] = _State, {call, test1, Value} = _Request, Session) ->
20 io:format("Request = ~p~n", [_Request]),
21 IPStr = io_lib:format("Client ip is ~p~n" , [ IP ]),
22 OldSession = io_lib:format("Request is: ~p~nOld session value "
23 "is ~p~n", [ _Request, Session ]),
24
25 case Session of
26 undefined -> % create new session
27 NewSession = 0;
28 10 -> % reset session after reaching 10
29 NewSession = undefined;
30 N ->
31 NewSession = N + 1
32 end,
33
34 NewVal = io_lib:format("New session value is ~p ~n", [ NewSession ]),
35 Str = lists:flatten([IPStr,OldSession,NewVal]),
36 {true, 0, NewSession, {response, Str }}.
37
38
39 </erl>
Something went wrong with that request. Please try again.