Improve websocket example in README.md

fix #138

* Refactoring for clarity
This commit is contained in:
Denis Andrejew
2016-10-15 01:58:26 +02:00
committed by Vinnie Falco
parent ae58a7f457
commit 753281959e
3 changed files with 6 additions and 4 deletions

View File

@@ -13,6 +13,7 @@
* Fix handling of body_what::pause in basic_parser_v1
* Add headers_parser
* Engaged invokable is destructible
* Improve websocket example in README.md
API Changes:
@@ -45,6 +46,7 @@ API Changes:
* Relax ForwardIterator requirements in FieldSequence
* Fix websocket failure testing
* Refine Writer concept and fix exemplar in documentation
* Improve websocket example
API Changes:

View File

@@ -171,14 +171,14 @@ int main()
// WebSocket connect and send message using beast
beast::websocket::stream<boost::asio::ip::tcp::socket&> ws{sock};
ws.handshake(host, "/");
ws.write(boost::asio::buffer("Hello, world!"));
ws.write(boost::asio::buffer(std::string("Hello, world!")));
// Receive WebSocket message, print and close using beast
beast::streambuf sb;
beast::websocket::opcode op;
ws.read(op, sb);
ws.close(beast::websocket::close_code::normal);
std::cout << to_string(sb.data()) << "\n";
std::cout << beast::to_string(sb.data()) << "\n";
}
```

View File

@@ -24,12 +24,12 @@ int main()
// WebSocket connect and send message using beast
beast::websocket::stream<boost::asio::ip::tcp::socket&> ws{sock};
ws.handshake(host, "/");
ws.write(boost::asio::buffer("Hello, world!"));
ws.write(boost::asio::buffer(std::string("Hello, world!")));
// Receive WebSocket message, print and close using beast
beast::streambuf sb;
beast::websocket::opcode op;
ws.read(op, sb);
ws.close(beast::websocket::close_code::normal);
std::cout << to_string(sb.data()) << "\n";
std::cout << beast::to_string(sb.data()) << "\n";
}