-
-
Save xim/06d60c455363fbb764c14f21d7705c40 to your computer and use it in GitHub Desktop.
Reproducing https://github.com/boostorg/beast/issues/2716
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/example/websocket/client/async/websocket_client_async.cpp b/example/websocket/client/async/websocket_client_async.cpp | |
index 5fcf721b..09550aee 100644 | |
--- a/example/websocket/client/async/websocket_client_async.cpp | |
+++ b/example/websocket/client/async/websocket_client_async.cpp | |
@@ -28,6 +28,8 @@ namespace websocket = beast::websocket; // from <boost/beast/websocket.hpp> | |
namespace net = boost::asio; // from <boost/asio.hpp> | |
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> | |
+using namespace std::chrono_literals; | |
+ | |
//------------------------------------------------------------------------------ | |
// Report a failure | |
@@ -106,8 +108,14 @@ public: | |
// Set suggested timeout settings for the websocket | |
ws_.set_option( | |
- websocket::stream_base::timeout::suggested( | |
- beast::role_type::client)); | |
+ websocket::stream_base::timeout{ | |
+ 3s, | |
+ 5s, | |
+ false | |
+ }); | |
+ ws_.control_callback([](auto type, auto const &) { | |
+ std::cerr << (type == decltype(type)::ping ? "ping" : "other") << std::endl; | |
+ }); | |
// Set a decorator to change the User-Agent of the handshake | |
ws_.set_option(websocket::stream_base::decorator( | |
@@ -172,10 +180,11 @@ public: | |
if(ec) | |
return fail(ec, "read"); | |
- // Close the WebSocket connection | |
- ws_.async_close(websocket::close_code::normal, | |
+ // Read a message into our buffer | |
+ ws_.async_read( | |
+ buffer_, | |
beast::bind_front_handler( | |
- &session::on_close, | |
+ &session::on_read, | |
shared_from_this())); | |
} | |
diff --git a/example/websocket/server/async/websocket_server_async.cpp b/example/websocket/server/async/websocket_server_async.cpp | |
index c50ac0cb..2861da52 100644 | |
--- a/example/websocket/server/async/websocket_server_async.cpp | |
+++ b/example/websocket/server/async/websocket_server_async.cpp | |
@@ -32,6 +32,8 @@ namespace websocket = beast::websocket; // from <boost/beast/websocket.hpp> | |
namespace net = boost::asio; // from <boost/asio.hpp> | |
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> | |
+using namespace std::chrono_literals; | |
+ | |
//------------------------------------------------------------------------------ | |
// Report a failure | |
@@ -75,8 +77,14 @@ public: | |
{ | |
// Set suggested timeout settings for the websocket | |
ws_.set_option( | |
- websocket::stream_base::timeout::suggested( | |
- beast::role_type::server)); | |
+ websocket::stream_base::timeout{ | |
+ 3s, | |
+ 2s, | |
+ true | |
+ }); | |
+ ws_.control_callback([](auto type, auto const &) { | |
+ std::cerr << (type == decltype(type)::pong ? "pong" : "other") << std::endl; | |
+ }); | |
// Set a decorator to change the Server of the handshake | |
ws_.set_option(websocket::stream_base::decorator( |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment