1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>websocket::stream::handshake (1 of 4 overloads)</title> 5<link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../../../index.html" title="Chapter 1. Boost.Beast"> 8<link rel="up" href="../handshake.html" title="websocket::stream::handshake"> 9<link rel="prev" href="../handshake.html" title="websocket::stream::handshake"> 10<link rel="next" href="overload2.html" title="websocket::stream::handshake (2 of 4 overloads)"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td> 15<td align="center"><a href="../../../../../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="../handshake.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../handshake.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="overload2.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h6 class="title"> 27<a name="beast.ref.boost__beast__websocket__stream.handshake.overload1"></a><a class="link" href="overload1.html" title="websocket::stream::handshake (1 of 4 overloads)">websocket::stream::handshake 28 (1 of 4 overloads)</a> 29</h6></div></div></div> 30<p> 31 Perform the WebSocket handshake in the client role. 32 </p> 33<h7><a name="beast.ref.boost__beast__websocket__stream.handshake.overload1.h0"></a> 34 <span class="phrase"><a name="beast.ref.boost__beast__websocket__stream.handshake.overload1.synopsis"></a></span><a class="link" href="overload1.html#beast.ref.boost__beast__websocket__stream.handshake.overload1.synopsis">Synopsis</a> 35 </h7><pre class="programlisting"><span class="keyword">void</span> 36<span class="identifier">handshake</span><span class="special">(</span> 37 <span class="identifier">string_view</span> <span class="identifier">host</span><span class="special">,</span> 38 <span class="identifier">string_view</span> <span class="identifier">target</span><span class="special">);</span> 39</pre> 40<h7><a name="beast.ref.boost__beast__websocket__stream.handshake.overload1.h1"></a> 41 <span class="phrase"><a name="beast.ref.boost__beast__websocket__stream.handshake.overload1.description"></a></span><a class="link" href="overload1.html#beast.ref.boost__beast__websocket__stream.handshake.overload1.description">Description</a> 42 </h7><p> 43 This function is used to perform the <a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake" target="_top">WebSocket 44 handshake</a>, required before messages can be sent and received. 45 During the handshake, the client sends the Websocket Upgrade HTTP request, 46 and the server replies with an HTTP response indicating the result of 47 the handshake. The call blocks until one of the following conditions 48 is true: 49 </p> 50<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 51<li class="listitem"> 52 The request is sent and the response is received. 53 </li> 54<li class="listitem"> 55 An error occurs. 56 </li> 57</ul></div> 58<p> 59 The algorithm, known as a <span class="emphasis"><em>composed operation</em></span>, is 60 implemented in terms of calls to the next layer's <code class="computeroutput"><span class="identifier">read_some</span></code> 61 and <code class="computeroutput"><span class="identifier">write_some</span></code> functions. 62 The handshake is successful if the received HTTP response indicates the 63 upgrade was accepted by the server, represented by a <a href="https://tools.ietf.org/html/rfc7230#section-3.1.2" target="_top">status-code</a> 64 of <a class="link" href="../../boost__beast__http__status.html" title="http::status"><code class="computeroutput"><span class="identifier">beast</span><span class="special">::</span><span class="identifier">http</span><span class="special">::</span><span class="identifier">status</span><span class="special">::</span><span class="identifier">switching_protocols</span></code></a>. 65 </p> 66<h7><a name="beast.ref.boost__beast__websocket__stream.handshake.overload1.h2"></a> 67 <span class="phrase"><a name="beast.ref.boost__beast__websocket__stream.handshake.overload1.parameters"></a></span><a class="link" href="overload1.html#beast.ref.boost__beast__websocket__stream.handshake.overload1.parameters">Parameters</a> 68 </h7><div class="informaltable"><table class="table"> 69<colgroup> 70<col> 71<col> 72</colgroup> 73<thead><tr> 74<th> 75 <p> 76 Name 77 </p> 78 </th> 79<th> 80 <p> 81 Description 82 </p> 83 </th> 84</tr></thead> 85<tbody> 86<tr> 87<td> 88 <p> 89 <code class="computeroutput"><span class="identifier">host</span></code> 90 </p> 91 </td> 92<td> 93 <p> 94 The name of the remote host. This is required by the HTTP protocol 95 to set the "Host" header field. 96 </p> 97 </td> 98</tr> 99<tr> 100<td> 101 <p> 102 <code class="computeroutput"><span class="identifier">target</span></code> 103 </p> 104 </td> 105<td> 106 <p> 107 The request-target, in origin-form. The server may use the 108 target to distinguish different services on the same listening 109 port. 110 </p> 111 </td> 112</tr> 113</tbody> 114</table></div> 115<h7><a name="beast.ref.boost__beast__websocket__stream.handshake.overload1.h3"></a> 116 <span class="phrase"><a name="beast.ref.boost__beast__websocket__stream.handshake.overload1.exceptions"></a></span><a class="link" href="overload1.html#beast.ref.boost__beast__websocket__stream.handshake.overload1.exceptions">Exceptions</a> 117 </h7><div class="informaltable"><table class="table"> 118<colgroup> 119<col> 120<col> 121</colgroup> 122<thead><tr> 123<th> 124 <p> 125 Type 126 </p> 127 </th> 128<th> 129 <p> 130 Thrown On 131 </p> 132 </th> 133</tr></thead> 134<tbody><tr> 135<td> 136 <p> 137 <code class="computeroutput"><span class="identifier">system_error</span></code> 138 </p> 139 </td> 140<td> 141 <p> 142 Thrown on failure. 143 </p> 144 </td> 145</tr></tbody> 146</table></div> 147<h7><a name="beast.ref.boost__beast__websocket__stream.handshake.overload1.h4"></a> 148 <span class="phrase"><a name="beast.ref.boost__beast__websocket__stream.handshake.overload1.example"></a></span><a class="link" href="overload1.html#beast.ref.boost__beast__websocket__stream.handshake.overload1.example">Example</a> 149 </h7><pre class="programlisting"><span class="identifier">ws</span><span class="special">.</span><span class="identifier">handshake</span><span class="special">(</span><span class="string">"localhost"</span><span class="special">,</span> <span class="string">"/"</span><span class="special">);</span> 150</pre> 151<h7><a name="beast.ref.boost__beast__websocket__stream.handshake.overload1.h5"></a> 152 <span class="phrase"><a name="beast.ref.boost__beast__websocket__stream.handshake.overload1.see_also"></a></span><a class="link" href="overload1.html#beast.ref.boost__beast__websocket__stream.handshake.overload1.see_also">See 153 Also</a> 154 </h7><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 155<li class="listitem"> 156 <a href="https://tools.ietf.org/html/rfc6455#section-4.1" target="_top">Websocket 157 Opening Handshake Client Requirements (RFC6455)</a> 158 </li> 159<li class="listitem"> 160 <a href="https://tools.ietf.org/html/rfc7230#section-5.4" target="_top">Host 161 field (RFC7230)</a> 162 </li> 163<li class="listitem"> 164 <a href="https://tools.ietf.org/html/rfc7230#section-3.1.1" target="_top">request-target 165 (RFC7230)</a> 166 </li> 167<li class="listitem"> 168 <a href="https://tools.ietf.org/html/rfc7230#section-5.3.1" target="_top">origin-form 169 (RFC7230)</a> 170 </li> 171</ul></div> 172</div> 173<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 174<td align="left"></td> 175<td align="right"><div class="copyright-footer">Copyright © 2016-2019 Vinnie 176 Falco<p> 177 Distributed under the Boost Software License, Version 1.0. (See accompanying 178 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) 179 </p> 180</div></td> 181</tr></table> 182<hr> 183<div class="spirit-nav"> 184<a accesskey="p" href="../handshake.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../handshake.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="overload2.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 185</div> 186</body> 187</html> 188