Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 40 lines (28 sloc) 1.122 kb
39c8d49 @jbothma update WebSockets implementation to support RFC 6455
jbothma authored
1 %%%===========================================================
2 %%% compiled using erlc -I include src/basic_echo_callback.erl
3 %%%===========================================================
4
5 -module(basic_echo_callback).
6
7 %% Export for websocket callbacks
8 -export([handle_message/1]).
9
10 %% Export for apply
11 -export([say_hi/1]).
12
13 handle_message({text, <<"bye">>}) ->
14 io:format("User said bye.~n", []),
15 {close, normal};
16
17 handle_message({text, <<"something">>}) ->
18 io:format("Some action without a reply~n", []),
19 noreply;
20
21 handle_message({text, <<"say hi later">>}) ->
22 io:format("saying hi in 3s.~n", []),
23 timer:apply_after(3000, ?MODULE, say_hi, [self()]),
24 {reply, {text, <<"I'll say hi in a bit...">>}};
25
26 handle_message({text, Message}) ->
27 io:format("basic echo handler got ~p~n", [Message]),
28 {reply, {text, <<Message/binary>>}};
29
30 handle_message({binary, Message}) ->
16834ce @vinoski add close callback for websockets
vinoski authored
31 {reply, {binary, Message}};
32
33 handle_message({close, _Status, _Reason}) ->
34 {close, normal}.
39c8d49 @jbothma update WebSockets implementation to support RFC 6455
jbothma authored
35
36
37 say_hi(Pid) ->
38 io:format("asynchronous greeting~n", []),
39 yaws_api:websocket_send(Pid, {text, <<"hi there!">>}).
Something went wrong with that request. Please try again.