2010-09-10 17:14:58 +02:00
|
|
|
-module (websocket_test).
|
2010-09-13 14:23:42 +02:00
|
|
|
-export([start/1, loop/1]).
|
2010-09-10 17:14:58 +02:00
|
|
|
|
|
|
|
% callback on received websockets data
|
2010-09-13 14:23:42 +02:00
|
|
|
start(Ws) ->
|
|
|
|
spawn(?MODULE, loop, [Ws]).
|
|
|
|
|
|
|
|
loop(Ws) ->
|
2010-09-10 17:14:58 +02:00
|
|
|
receive
|
|
|
|
{browser, Data} ->
|
|
|
|
Ws:send(["received '", Data, "'"]),
|
2010-09-13 14:23:42 +02:00
|
|
|
loop(Ws);
|
2010-09-10 17:14:58 +02:00
|
|
|
_Ignore ->
|
2010-09-13 14:23:42 +02:00
|
|
|
loop(Ws)
|
2010-09-10 17:14:58 +02:00
|
|
|
after 5000 ->
|
|
|
|
Ws:send("pushing!"),
|
2010-09-13 14:23:42 +02:00
|
|
|
loop(Ws)
|
2010-09-10 17:14:58 +02:00
|
|
|
end.
|