]>
git.proxmox.com Git - ceph.git/blob - ceph/src/Beast/examples/ssl/websocket_ssl_example.cpp
2 // Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 #include <beast/core/to_string.hpp>
9 #include <beast/websocket.hpp>
10 #include <beast/websocket/ssl.hpp>
11 #include <boost/asio.hpp>
12 #include <boost/asio/ssl.hpp>
18 using boost::asio::connect
;
19 using socket
= boost::asio::ip::tcp::socket
;
20 using resolver
= boost::asio::ip::tcp::resolver
;
21 using io_service
= boost::asio::io_service
;
22 namespace ssl
= boost::asio::ssl
;
24 // Normal boost::asio setup
25 std::string
const host
= "echo.websocket.org";
29 connect(sock
, r
.resolve(resolver::query
{host
, "https"}));
31 // Perform SSL handshaking
32 using stream_type
= ssl::stream
<socket
&>;
33 ssl::context ctx
{ssl::context::sslv23
};
34 stream_type stream
{sock
, ctx
};
35 stream
.set_verify_mode(ssl::verify_none
);
36 stream
.handshake(ssl::stream_base::client
);
38 // Secure WebSocket connect and send message using Beast
39 beast::websocket::stream
<stream_type
&> ws
{stream
};
40 ws
.handshake(host
, "/");
41 ws
.write(boost::asio::buffer("Hello, world!"));
43 // Receive Secure WebSocket message, print and close using Beast
45 beast::websocket::opcode op
;
47 ws
.close(beast::websocket::close_code::normal
);
48 std::cout
<< to_string(sb
.data()) << "\n";