]>
git.proxmox.com Git - ceph.git/blob - ceph/src/Beast/examples/websocket_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 <boost/asio.hpp>
16 // Normal boost::asio setup
17 std::string
const host
= "echo.websocket.org";
18 boost::asio::io_service ios
;
19 boost::asio::ip::tcp::resolver r
{ios
};
20 boost::asio::ip::tcp::socket sock
{ios
};
21 boost::asio::connect(sock
,
22 r
.resolve(boost::asio::ip::tcp::resolver::query
{host
, "80"}));
24 // WebSocket connect and send message using beast
25 beast::websocket::stream
<boost::asio::ip::tcp::socket
&> ws
{sock
};
26 ws
.handshake(host
, "/");
27 ws
.write(boost::asio::buffer(std::string("Hello, world!")));
29 // Receive WebSocket message, print and close using beast
31 beast::websocket::opcode op
;
33 ws
.close(beast::websocket::close_code::normal
);
34 std::cout
<< beast::to_string(sb
.data()) << "\n";