Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 45D9717C8E for ; Mon, 29 Jun 2015 21:46:11 +0000 (UTC) Received: (qmail 13692 invoked by uid 500); 29 Jun 2015 21:46:08 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 13513 invoked by uid 500); 29 Jun 2015 21:46:08 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 12674 invoked by uid 99); 29 Jun 2015 21:46:08 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 29 Jun 2015 21:46:08 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id F2F06E35D6; Mon, 29 Jun 2015 21:46:07 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: robertkowalski@apache.org To: commits@couchdb.apache.org Date: Mon, 29 Jun 2015 21:46:31 -0000 Message-Id: In-Reply-To: <41909276fb954bfdb4649bc815a971dd@git.apache.org> References: <41909276fb954bfdb4649bc815a971dd@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [25/50] couch commit: updated refs/heads/COUCHDB-2734-header-date to f3e022c documentation for websocket example Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/ecb1eba1 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/ecb1eba1 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/ecb1eba1 Branch: refs/heads/COUCHDB-2734-header-date Commit: ecb1eba135ce140c16cc58316b7fb20e5d1a39c8 Parents: 3961edc Author: Łukasz Lalik Authored: Wed Dec 25 13:46:08 2013 +0100 Committer: Łukasz Lalik Committed: Wed Dec 25 13:46:08 2013 +0100 ---------------------------------------------------------------------- examples/websocket/websocket.erl | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/ecb1eba1/examples/websocket/websocket.erl ---------------------------------------------------------------------- diff --git a/examples/websocket/websocket.erl b/examples/websocket/websocket.erl index b70a0de..7039e42 100644 --- a/examples/websocket/websocket.erl +++ b/examples/websocket/websocket.erl @@ -24,7 +24,28 @@ -export([start_link/0, ws_loop/3, loop/1]). +% +% Mochiweb websocket example +% +% [1]: At first you have to start HTTP server which will listen for HTTP requests +% and eventually upgrade connection to websocket +% [2]: Attempt to upgrade connection to websocket. +% Function mochiweb_websocket:upgrade_connection/2: +% * first argument is mochiweb_request +% * second is M:F which will handle further websocket messages. +% Function return two funs: +% * ReentryWs/1 - use it to enter to messages handling loop (in this example ws_loop/3) +% * ReplyChannel/1 - use to send messages to client. May be passed to other processes +% [3]: Example of sending message to client +% [4]: State that will be passed to message handling loop +% [5]: Pass controll to messages handling loop. From this moment each message received from client +% can be handled... +% [6]: ...here as Payload. State is variable intended for holiding your custom state. ReplyChannel +% is the same function as in [3]. +% [7]: Print payload received from client and send it back +% [8]: Message handling function must return new state value start_link() -> + % [1] Loop = fun (Req) -> ?MODULE:loop(Req) end, @@ -36,13 +57,24 @@ start_link() -> ]). ws_loop(Payload, State, ReplyChannel) -> + % [6] + + % [7] io:format("Received data: ~p~n", [Payload]), Received = list_to_binary(Payload), ReplyChannel(<<"Received ", Received/binary>>), + + % [8] State. loop(Req) -> + % [2] {ReentryWs, ReplyChannel} = mochiweb_websocket:upgrade_connection(Req, {?MODULE, ws_loop}), + + % [3] ReplyChannel(<<"Hello">>), + + % [4] InitialState = [], + % [5] ReentryWs(InitialState).