Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 61 lines (41 sloc) 2.155 kb
785b7c6 Davide Added documentation for the HTML5 Web Sockets implementation.
davide authored
1 <erl>
2
3
4 box(Str) ->
5 {'div',[{class,"box"}],
6 {pre,[],yaws_api:htmlize(Str)}}.
7
8 tbox(T) ->
9 box(lists:flatten(io_lib:format("~p",[T]))).
10
11
12 ssi(File) ->
13 {'div',[{class,"box"}],
14 {pre,[],
15 {ssi, File,[],[]}}}.
16
17
18 out(A) ->
19 [{ssi, "TAB.inc", "%%",[{"websockets", "choosen"}]},
20 {ehtml,
21 {'div',[{id, "entry"}],
22 [{h1, [], "Web Sockets in Yaws"},
23
24 {p, [], ["Web Sockets! The new kid in town! Joe ", {a, [{href, "http://armstrongonsoftware.blogspot.com/2009/12/comet-is-dead-long-live-websockets.html"}], "loves it"}, ", maybe you should too?"]},
25
26 {p, [], "Web Sockets allow for *real* two-way communication between the browser and Yaws without the overhead and latency that come with polling/long-polling solutions. That should be enough for an introduction. Now... how to use it?"},
7811247 Steve Vinoski whitespace cleanup
vinoski authored
27
785b7c6 Davide Added documentation for the HTML5 Web Sockets implementation.
davide authored
28 {p, [], "First start by returning:"},
29
39c8d49 JD Bothma update WebSockets implementation to support RFC 6455
jbothma authored
30 box(" {websocket, CallbackMod, Options}"),
31
32 {p,[], "from the out/1 function, where CallbackMod is an atom identifying your Websocket callback module, and Options can be an empty list."
33 " This makes the erlang process within yaws processing that particular page do a protocol upgrade from HTTP to the Web Socket Protocol, after which messages received by the server call handle_message in the callback module, and messages can be sent on the Websocket using yaws_api:websocket_send/2."},
34 {p, [], "The callback module should implement a function handle_message as follows:"},
35 box("handle_message({Type, Data}) -> HandlerResult
36 Type :: text|binary
37 Data :: binary()
38 HandlerResult :: {reply, {Type, Data}}
6e10bf2 Andrei Soroker Update www/websockets.yaws
abs authored
39 | noreply
39c8d49 JD Bothma update WebSockets implementation to support RFC 6455
jbothma authored
40 | {close, Reason}"),
41 {p, [], "When not replying to a message from a client, you can send messages using"},
42 box("yaws_api:websocket_send(Pid, {Type, Data})"),
785b7c6 Davide Added documentation for the HTML5 Web Sockets implementation.
davide authored
43 {p, [], "Enough theory for now. Sample echo server follows!"},
44
45 ssi("websockets_example_endpoint.yaws"),
46
47 {p, [],
48 ["The above code can be executed ",
49 {a, [{href, "websockets_example.yaws"}], "Here"},
50 "."]}
51
52 ]}},
53 {ssi, "END2",[],[]}
54 ].
55
56
57 </erl>
58
59
60 </html>
Something went wrong with that request. Please try again.