diff --git a/examples/README.md b/examples/README.md
index f2b0c642..fa197c73 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -28,3 +28,6 @@ Cowboy Examples
* [static](./examples/static):
an example file server
+
+ * [static](./examples/websocket):
+ websocket example
\ No newline at end of file
diff --git a/examples/websocket/README.md b/examples/websocket/README.md
new file mode 100644
index 00000000..14f6f746
--- /dev/null
+++ b/examples/websocket/README.md
@@ -0,0 +1,17 @@
+Cowboy websocket
+================
+
+To compile this example you need rebar in your PATH.
+
+Type the following command:
+```
+$ rebar get-deps compile
+```
+
+You can then start the Erlang node with the following command:
+```
+./start.sh
+```
+
+Then point your browser to the indicated URL to open a websocket client.
+Not all browsers suport websockets. It was tested with Chromium.
diff --git a/examples/websocket/priv/html_ws_client.html b/examples/websocket/priv/html_ws_client.html
new file mode 100644
index 00000000..a7d24ca4
--- /dev/null
+++ b/examples/websocket/priv/html_ws_client.html
@@ -0,0 +1,108 @@
+
+
+
+ Websocket client
+
+
+
+
+
+
+
Websocket client
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/websocket/rebar.config b/examples/websocket/rebar.config
new file mode 100644
index 00000000..6ad30625
--- /dev/null
+++ b/examples/websocket/rebar.config
@@ -0,0 +1,4 @@
+{deps, [
+ {cowboy, ".*",
+ {git, "git://github.com/extend/cowboy.git", "master"}}
+]}.
diff --git a/examples/websocket/src/toppage_handler.erl b/examples/websocket/src/toppage_handler.erl
new file mode 100644
index 00000000..63099b0a
--- /dev/null
+++ b/examples/websocket/src/toppage_handler.erl
@@ -0,0 +1,24 @@
+%% Feel free to use, reuse and abuse the code in this file.
+
+-module(toppage_handler).
+
+-export([init/3]).
+-export([handle/2]).
+-export([terminate/3]).
+
+init(_Transport, Req, []) ->
+ {ok, Req, undefined}.
+
+handle(Req, State) ->
+ Html = get_html(),
+ {ok, Req2} = cowboy_req:reply(200, [], Html, Req),
+ {ok, Req2, State}.
+
+terminate(_Reason, _Req, _State) ->
+ ok.
+
+get_html() ->
+ {ok, Cwd} = file:get_cwd(),
+ Filename =filename:join([Cwd, "priv", "html_ws_client.html"]),
+ {ok, Binary} = file:read_file(Filename),
+ Binary.
diff --git a/examples/websocket/src/websocket.app.src b/examples/websocket/src/websocket.app.src
new file mode 100644
index 00000000..4fa4f785
--- /dev/null
+++ b/examples/websocket/src/websocket.app.src
@@ -0,0 +1,15 @@
+%% Feel free to use, reuse and abuse the code in this file.
+
+{application, websocket, [
+ {description, "Cowboy websocket example."},
+ {vsn, "1"},
+ {modules, []},
+ {registered, []},
+ {applications, [
+ kernel,
+ stdlib,
+ cowboy
+ ]},
+ {mod, {websocket_app, []}},
+ {env, []}
+]}.
diff --git a/examples/websocket/src/websocket.erl b/examples/websocket/src/websocket.erl
new file mode 100644
index 00000000..da2a91cc
--- /dev/null
+++ b/examples/websocket/src/websocket.erl
@@ -0,0 +1,12 @@
+%% Feel free to use, reuse and abuse the code in this file.
+
+-module(websocket).
+
+%% API.
+-export([start/0]).
+
+start() ->
+ ok = application:start(crypto),
+ ok = application:start(ranch),
+ ok = application:start(cowboy),
+ ok = application:start(websocket).
diff --git a/examples/websocket/src/websocket_app.erl b/examples/websocket/src/websocket_app.erl
new file mode 100644
index 00000000..5dc70171
--- /dev/null
+++ b/examples/websocket/src/websocket_app.erl
@@ -0,0 +1,24 @@
+%% Feel free to use, reuse and abuse the code in this file.
+
+%% @private
+-module(websocket_app).
+-behaviour(application).
+
+%% API.
+-export([start/2]).
+-export([stop/1]).
+
+%% API.
+start(_Type, _Args) ->
+ Dispatch = cowboy_router:compile([
+ {'_', [
+ {"/", toppage_handler, []},
+ {"/websocket", ws_handler, []}
+ ]}
+ ]),
+ {ok, _} = cowboy:start_http(http, 100, [{port, 8080}],
+ [{env, [{dispatch, Dispatch}]}]),
+ websocket_sup:start_link().
+
+stop(_State) ->
+ ok.
diff --git a/examples/websocket/src/websocket_sup.erl b/examples/websocket/src/websocket_sup.erl
new file mode 100644
index 00000000..40ef8e07
--- /dev/null
+++ b/examples/websocket/src/websocket_sup.erl
@@ -0,0 +1,23 @@
+%% Feel free to use, reuse and abuse the code in this file.
+
+%% @private
+-module(websocket_sup).
+-behaviour(supervisor).
+
+%% API.
+-export([start_link/0]).
+
+%% supervisor.
+-export([init/1]).
+
+%% API.
+
+-spec start_link() -> {ok, pid()}.
+start_link() ->
+ supervisor:start_link({local, ?MODULE}, ?MODULE, []).
+
+%% supervisor.
+
+init([]) ->
+ Procs = [],
+ {ok, {{one_for_one, 10, 10}, Procs}}.
diff --git a/examples/websocket/src/ws_handler.erl b/examples/websocket/src/ws_handler.erl
new file mode 100644
index 00000000..bbbf716d
--- /dev/null
+++ b/examples/websocket/src/ws_handler.erl
@@ -0,0 +1,29 @@
+-module(ws_handler).
+-behaviour(cowboy_websocket_handler).
+
+-export([init/3]).
+-export([websocket_init/3]).
+-export([websocket_handle/3]).
+-export([websocket_info/3]).
+-export([websocket_terminate/3]).
+
+init({tcp, http}, _Req, _Opts) ->
+ {upgrade, protocol, cowboy_websocket}.
+
+websocket_init(_TransportName, Req, _Opts) ->
+ erlang:start_timer(1000, self(), <<"Hello!">>),
+ {ok, Req, undefined_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_info({timeout, _Ref, Msg}, Req, State) ->
+ erlang:start_timer(1000, self(), <<"How' you doin'?">>),
+ {reply, {text, Msg}, Req, State};
+websocket_info(_Info, Req, State) ->
+ {ok, Req, State}.
+
+websocket_terminate(_Reason, _Req, _State) ->
+ ok.
diff --git a/examples/websocket/start.sh b/examples/websocket/start.sh
new file mode 100755
index 00000000..d2ad16a1
--- /dev/null
+++ b/examples/websocket/start.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+erl -pa ebin deps/*/ebin -s websocket \
+ -eval "io:format(\"Point your browser at http://localhost:8080/ to use a simple websocket client~n\")."
+