From 8459bebceb9533948193774371cbd9fd571b78ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Wed, 16 Oct 2019 09:48:31 +0200 Subject: Cowboy 2.7.0 --- docs/en/gun/2.0/guide/websocket/index.html | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'docs/en/gun/2.0/guide/websocket') diff --git a/docs/en/gun/2.0/guide/websocket/index.html b/docs/en/gun/2.0/guide/websocket/index.html index e58212ad..fcc8ecce 100644 --- a/docs/en/gun/2.0/guide/websocket/index.html +++ b/docs/en/gun/2.0/guide/websocket/index.html @@ -68,7 +68,7 @@

Websocket is a protocol built on top of HTTP. To use Websocket, you must first request for the connection to be upgraded. Only HTTP/1.1 connections can be upgraded to Websocket, so you might need to restrict the protocol to HTTP/1.1 if you are planning to use Websocket over TLS.

You must use the gun:ws_upgrade/2,3,4 function to upgrade to Websocket. This function can be called anytime after connection, so you can send HTTP requests before upgrading to Websocket.

Upgrade to Websocket
-
@@ -76,7 +76,7 @@ http://www.gnu.org/software/src-highlite -->

Gun will set all the necessary headers for performing the Websocket upgrade, but you can specify additional headers if needed. For example you can authenticate.

Upgrade to Websocket using HTTP authentication
-
@@ -87,7 +87,7 @@ http://www.gnu.org/software/src-highlite -->

You can pass the Websocket options as part of the gun:open/2,3 call when opening the connection, or using the gun:ws_upgrade/4. The fourth argument is those same options.

Gun can negotiate the protocol to be used for the Websocket connection. The protocols option can be given with a list of protocols accepted and the corresponding handler module. Note that the interface for handler modules is currently undocumented and must be set to gun_ws_h.

Upgrade to Websocket with protocol negotiation
-
@@ -97,7 +97,7 @@ http://www.gnu.org/software/src-highlite -->

The upgrade will fail if the server cannot satisfy the protocol negotiation.

When the upgrade succeeds, a gun_upgrade message is sent. If the server does not understand Websocket or refused the upgrade, a gun_response message is sent. If Gun couldn't perform the upgrade due to an error (for example attempting to upgrade to Websocket on an HTTP/1.0 connection) then a gun_error message is sent.

When the server does not understand Websocket, it may send a meaningful response which should be processed. In the following example we however ignore it:

-
@@ -117,14 +117,14 @@ http://www.gnu.org/software/src-highlite -->

Once the Websocket upgrade has completed successfully, you no longer have access to functions for performing requests. You can only send and receive Websocket messages.

Use gun:ws_send/2 to send messages to the server.

Send a text frame
-
gun:ws_send(ConnPid, {text, "Hello!"}).
Send a text frame, a binary frame and then close the connection
-
@@ -137,7 +137,7 @@ http://www.gnu.org/software/src-highlite -->

Note that if you send a close frame, Gun will close the connection cleanly but may attempt to reconnect afterwards depending on the retry configuration.

Receiving data

Gun sends an Erlang message to the owner process for every Websocket message it receives.

-
-- cgit v1.2.3