diff options
author | Loïc Hoguin <[email protected]> | 2016-08-29 12:39:49 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2016-08-29 12:40:03 +0200 |
commit | c807880f7ac73f813b2660ea81a00f7712a4e793 (patch) | |
tree | ba1d09e9b177f230665a80513b33fbd532000ce4 /docs/en/cowboy/2.0/guide/ws_handlers.asciidoc | |
parent | b1df25a7d9cda697513650659b781b55b40898f8 (diff) | |
download | ninenines.eu-c807880f7ac73f813b2660ea81a00f7712a4e793.tar.gz ninenines.eu-c807880f7ac73f813b2660ea81a00f7712a4e793.tar.bz2 ninenines.eu-c807880f7ac73f813b2660ea81a00f7712a4e793.zip |
Add old mailing list archives
Diffstat (limited to 'docs/en/cowboy/2.0/guide/ws_handlers.asciidoc')
-rw-r--r-- | docs/en/cowboy/2.0/guide/ws_handlers.asciidoc | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/docs/en/cowboy/2.0/guide/ws_handlers.asciidoc b/docs/en/cowboy/2.0/guide/ws_handlers.asciidoc index 9ddddf4c..b280fd86 100644 --- a/docs/en/cowboy/2.0/guide/ws_handlers.asciidoc +++ b/docs/en/cowboy/2.0/guide/ws_handlers.asciidoc @@ -18,8 +18,8 @@ must return a `ws` tuple. [source,erlang] ---- -init(Req, _Opts) -> - {cowboy_websocket, Req, #state{}}. +init(Req, State) -> + {cowboy_websocket, Req, State}. ---- Upon receiving this tuple, Cowboy will switch to the code @@ -34,18 +34,18 @@ the connection, assuming no correct subprotocol was found. [source,erlang] ---- -init(Req, _Opts) -> +init(Req, State) -> case cowboy_req:parse_header(<<"sec-websocket-protocol">>, Req) of undefined -> - {ok, Req, #state{}}; + {ok, Req, State}; Subprotocols -> case lists:keymember(<<"mychat2">>, 1, Subprotocols) of true -> Req2 = cowboy_req:set_resp_header(<<"sec-websocket-protocol">>, <<"mychat2">>, Req), - {ok, Req2, #state{}}; + {ok, Req2, State}; false -> - {stop, Req, undefined} + {stop, Req, State} end end. ---- @@ -60,12 +60,14 @@ It is also very easy to ensure that this message arrives before any message from other processes by sending it before registering or enabling timers. +// @todo This doesn't even work. + [source,erlang] ---- -init(Req, _Opts) -> +init(Req, State) -> self() ! post_init, %% Register process here... - {cowboy_websocket, Req, #state{}}. + {cowboy_websocket, Req, State}. websocket_info(post_init, Req, State) -> %% Perform post_init initialization here... @@ -169,8 +171,8 @@ A good timeout value is 60 seconds. [source,erlang] ---- -init(Req, _Opts) -> - {cowboy_websocket, Req, #state{}, 60000}. +init(Req, State) -> + {cowboy_websocket, Req, State, 60000}. ---- This value cannot be changed once it is set. It defaults to |