aboutsummaryrefslogtreecommitdiffstats
path: root/guide/websocket.md
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2015-03-25 13:44:08 +0100
committerLoïc Hoguin <[email protected]>2015-03-25 13:44:08 +0100
commit83d8b63b8abb46b374439c8c8571091968af6260 (patch)
tree11a7bb370d43a7c25e4734eb7a6f7649ce9cdc61 /guide/websocket.md
parenteab45765497e6eb3e031cba5dad66a7a20ec3651 (diff)
downloadgun-83d8b63b8abb46b374439c8c8571091968af6260.tar.gz
gun-83d8b63b8abb46b374439c8c8571091968af6260.tar.bz2
gun-83d8b63b8abb46b374439c8c8571091968af6260.zip
Update the guide
A number of @todo remain in it and will be worked on shortly. The guide has been converted to Asciidoc and 'make asciidoc' will generate a PDF and a chunked HTML version.
Diffstat (limited to 'guide/websocket.md')
-rw-r--r--guide/websocket.md85
1 files changed, 0 insertions, 85 deletions
diff --git a/guide/websocket.md b/guide/websocket.md
deleted file mode 100644
index 26b73c2..0000000
--- a/guide/websocket.md
+++ /dev/null
@@ -1,85 +0,0 @@
-Using Websocket
-===============
-
-This chapter describes how to use the Gun client for
-communicating with a Websocket server.
-
-HTTP upgrade
-------------
-
-Websocket is a protocol built on top of HTTP. To use Websocket,
-you must first request for the connection to be upgraded.
-
-Gun allows you to perform Websocket upgrade requests by using
-the `gun:ws_upgrade/{2,3}` function. Gun will fill out all
-necessary headers for performing the Websocket upgrade, but
-you can optionally specify additional headers, for example if
-you would like to setup a custom sub-protocol.
-
-``` erlang
-%% Without headers.
-gun:ws_upgrade(Pid, "/websocket").
-%% With headers.
-gun:ws_upgrade(Pid, "/websocket", [
- {"sec-websocket-protocol", "mychat"}
-]).
-```
-
-The success or failure of this operation will be sent as a
-message.
-
-``` erlang
-receive
- {gun_ws_upgrade, Pid, ok} ->
- upgrade_success(Pid);
- {gun_ws_upgrade, Pid, error, IsFin, Status, Headers} ->
- exit({ws_upgrade_failed, Status, Headers});
- %% More clauses here as needed.
-after 1000 ->
- exit(timeout);
-end.
-```
-
-Sending data
-------------
-
-You can then use the `gun:ws_send/2` function to send one or
-more frames to the server.
-
-``` erlang
-%% Send one text frame.
-gun:ws_send(Pid, {text, "Hello!"}).
-%% Send one text frame, one binary frame and close the connection.
-gun:ws_send(Pid, [
- {text, "Hello!"},
- {binary, SomeBin},
- close
-]).
-```
-
-Note that if you send a close frame, Gun will close the connection
-cleanly and will not attempt to reconnect afterwards, similar to
-calling `gun:shutdown/1`.
-
-Receiving data
---------------
-
-Every time Gun receives a frame from the server a message will be
-sent to the controlling process. This message will always contain
-a single frame.
-
-``` erlang
-receive
- {gun_ws, Pid, Frame} ->
- handle_frame(Pid, Frame);
- {gun_error, Pid, Reason} ->
- error_logger:error_msg("Oops! ~p~n", [Reason]),
- upgrade_again(Pid)
-end.
-```
-
-Gun will automatically send ping messages to the server to keep
-the connection alive, however if the connection dies and Gun has
-to reconnect it will not upgrade to Websocket automatically, you
-need to perform the operation when you receive the `gun_error`
-message.