websocket_example1.anubis
1.09 KB
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
$begin
Here is an example of a subprotocol handler that is as simple as possible.
The client browser sends a character string obtained from an input HTML
element, and the server returns the character string capitalized, that
replaces the content of the input element.
$acode(
read system/string.anubis
read http/websocket_handler.anubis
)
$acode(
define (TxtBin,WebSocketMessage) -> One
the_example1_handler
(
MaybeTicket mb_ticket,
(TxtBin,WebSocketMessage) -> Var(WebSocketSendControl) send_message,
One -> One close_connection
) =
(TxtBin tb, WebSocketMessage msg) |->
if to_string(msg) is
{
failure then unique,
success(s) then
forget(send_message(
tb,to_websocket_message(to_byte_array(to_upper(s)),1000)))
}.
)
Here is the secondary module.
$acode(
module WebSocketHandler
websocket_example1
=
websocket_handler
(
the_example1_handler
).
)
$end