forked from boostorg/beast
Improve websocket example in README.md
fix #138 * Refactoring for clarity
This commit is contained in:
committed by
Vinnie Falco
parent
ae58a7f457
commit
753281959e
@@ -13,6 +13,7 @@
|
|||||||
* Fix handling of body_what::pause in basic_parser_v1
|
* Fix handling of body_what::pause in basic_parser_v1
|
||||||
* Add headers_parser
|
* Add headers_parser
|
||||||
* Engaged invokable is destructible
|
* Engaged invokable is destructible
|
||||||
|
* Improve websocket example in README.md
|
||||||
|
|
||||||
API Changes:
|
API Changes:
|
||||||
|
|
||||||
@@ -45,6 +46,7 @@ API Changes:
|
|||||||
* Relax ForwardIterator requirements in FieldSequence
|
* Relax ForwardIterator requirements in FieldSequence
|
||||||
* Fix websocket failure testing
|
* Fix websocket failure testing
|
||||||
* Refine Writer concept and fix exemplar in documentation
|
* Refine Writer concept and fix exemplar in documentation
|
||||||
|
* Improve websocket example
|
||||||
|
|
||||||
API Changes:
|
API Changes:
|
||||||
|
|
||||||
|
@@ -171,14 +171,14 @@ int main()
|
|||||||
// WebSocket connect and send message using beast
|
// WebSocket connect and send message using beast
|
||||||
beast::websocket::stream<boost::asio::ip::tcp::socket&> ws{sock};
|
beast::websocket::stream<boost::asio::ip::tcp::socket&> ws{sock};
|
||||||
ws.handshake(host, "/");
|
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
|
// Receive WebSocket message, print and close using beast
|
||||||
beast::streambuf sb;
|
beast::streambuf sb;
|
||||||
beast::websocket::opcode op;
|
beast::websocket::opcode op;
|
||||||
ws.read(op, sb);
|
ws.read(op, sb);
|
||||||
ws.close(beast::websocket::close_code::normal);
|
ws.close(beast::websocket::close_code::normal);
|
||||||
std::cout << to_string(sb.data()) << "\n";
|
std::cout << beast::to_string(sb.data()) << "\n";
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@@ -24,12 +24,12 @@ int main()
|
|||||||
// WebSocket connect and send message using beast
|
// WebSocket connect and send message using beast
|
||||||
beast::websocket::stream<boost::asio::ip::tcp::socket&> ws{sock};
|
beast::websocket::stream<boost::asio::ip::tcp::socket&> ws{sock};
|
||||||
ws.handshake(host, "/");
|
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
|
// Receive WebSocket message, print and close using beast
|
||||||
beast::streambuf sb;
|
beast::streambuf sb;
|
||||||
beast::websocket::opcode op;
|
beast::websocket::opcode op;
|
||||||
ws.read(op, sb);
|
ws.read(op, sb);
|
||||||
ws.close(beast::websocket::close_code::normal);
|
ws.close(beast::websocket::close_code::normal);
|
||||||
std::cout << to_string(sb.data()) << "\n";
|
std::cout << beast::to_string(sb.data()) << "\n";
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user