ws_echo.erl 458 B

1234567891011121314151617181920
  1. %% Feel free to use, reuse and abuse the code in this file.
  2. -module(ws_echo).
  3. -export([init/2]).
  4. -export([websocket_handle/2]).
  5. -export([websocket_info/2]).
  6. init(Req, _) ->
  7. {cowboy_websocket, Req, undefined}.
  8. websocket_handle({text, Data}, State) ->
  9. {reply, {text, Data}, State};
  10. websocket_handle({binary, Data}, State) ->
  11. {reply, {binary, Data}, State};
  12. websocket_handle(_Frame, State) ->
  13. {ok, State}.
  14. websocket_info(_Info, State) ->
  15. {ok, State}.