0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 04:10:24 +00:00

Fix websocket example

This commit is contained in:
Witeman Zheng 2016-08-21 21:31:54 +08:00 committed by Loïc Hoguin
parent c750dd76b4
commit b9ad02d305

View file

@ -1,24 +1,24 @@
-module(ws_handler).
-export([init/2]).
-export([websocket_init/2]).
-export([websocket_handle/3]).
-export([websocket_info/3]).
-export([websocket_init/1]).
-export([websocket_handle/2]).
-export([websocket_info/2]).
init(Req, Opts) ->
{cowboy_websocket, Req, Opts}.
websocket_init(Req, State) ->
websocket_init(State) ->
erlang:start_timer(1000, self(), <<"Hello!">>),
{ok, Req, State}.
{ok, State}.
websocket_handle({text, Msg}, Req, State) ->
{reply, {text, << "That's what she said! ", Msg/binary >>}, Req, State};
websocket_handle(_Data, Req, State) ->
{ok, Req, State}.
websocket_handle({text, Msg}, State) ->
{reply, {text, << "That's what she said! ", Msg/binary >>}, State};
websocket_handle(_Data, State) ->
{ok, State}.
websocket_info({timeout, _Ref, Msg}, Req, State) ->
websocket_info({timeout, _Ref, Msg}, State) ->
erlang:start_timer(1000, self(), <<"How' you doin'?">>),
{reply, {text, Msg}, Req, State};
websocket_info(_Info, Req, State) ->
{ok, Req, State}.
{reply, {text, Msg}, State};
websocket_info(_Info, State) ->
{ok, State}.