mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Fix websocket example
This commit is contained in:
parent
c750dd76b4
commit
b9ad02d305
1 changed files with 13 additions and 13 deletions
|
@ -1,24 +1,24 @@
|
||||||
-module(ws_handler).
|
-module(ws_handler).
|
||||||
|
|
||||||
-export([init/2]).
|
-export([init/2]).
|
||||||
-export([websocket_init/2]).
|
-export([websocket_init/1]).
|
||||||
-export([websocket_handle/3]).
|
-export([websocket_handle/2]).
|
||||||
-export([websocket_info/3]).
|
-export([websocket_info/2]).
|
||||||
|
|
||||||
init(Req, Opts) ->
|
init(Req, Opts) ->
|
||||||
{cowboy_websocket, Req, Opts}.
|
{cowboy_websocket, Req, Opts}.
|
||||||
|
|
||||||
websocket_init(Req, State) ->
|
websocket_init(State) ->
|
||||||
erlang:start_timer(1000, self(), <<"Hello!">>),
|
erlang:start_timer(1000, self(), <<"Hello!">>),
|
||||||
{ok, Req, State}.
|
{ok, State}.
|
||||||
|
|
||||||
websocket_handle({text, Msg}, Req, State) ->
|
websocket_handle({text, Msg}, State) ->
|
||||||
{reply, {text, << "That's what she said! ", Msg/binary >>}, Req, State};
|
{reply, {text, << "That's what she said! ", Msg/binary >>}, State};
|
||||||
websocket_handle(_Data, Req, State) ->
|
websocket_handle(_Data, State) ->
|
||||||
{ok, Req, State}.
|
{ok, State}.
|
||||||
|
|
||||||
websocket_info({timeout, _Ref, Msg}, Req, State) ->
|
websocket_info({timeout, _Ref, Msg}, State) ->
|
||||||
erlang:start_timer(1000, self(), <<"How' you doin'?">>),
|
erlang:start_timer(1000, self(), <<"How' you doin'?">>),
|
||||||
{reply, {text, Msg}, Req, State};
|
{reply, {text, Msg}, State};
|
||||||
websocket_info(_Info, Req, State) ->
|
websocket_info(_Info, State) ->
|
||||||
{ok, Req, State}.
|
{ok, State}.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue