Updated examples using start callback

This commit is contained in:
eidheim 2019-12-30 18:53:02 +01:00
commit a5fcd2ba0d
2 changed files with 15 additions and 12 deletions

View file

@ -205,13 +205,15 @@ int main() {
// Note that connection timeouts will also call this handle with ec set to SimpleWeb::errc::operation_canceled
};
thread server_thread([&server]() {
// Start server and receive assigned port when server is listening for requests
promise<unsigned short> server_port;
thread server_thread([&server, &server_port]() {
// Start server
server.start();
server.start([&server_port](unsigned short port) {
server_port.set_value(port);
});
// Wait for server to start so that the client can connect
this_thread::sleep_for(chrono::seconds(1));
});
cout << "Server listening on port " << server_port.get_future().get() << endl << endl;
// Client examples
HttpClient client("localhost:8080");

View file

@ -203,17 +203,18 @@ int main() {
// Note that connection timeouts will also call this handle with ec set to SimpleWeb::errc::operation_canceled
};
thread server_thread([&server]() {
// Start server and receive assigned port when server is listening for requests
promise<unsigned short> server_port;
thread server_thread([&server, &server_port]() {
// Start server
server.start();
server.start([&server_port](unsigned short port) {
server_port.set_value(port);
});
// Wait for server to start so that the client can connect
this_thread::sleep_for(chrono::seconds(1));
});
cout << "Server listening on port " << server_port.get_future().get() << endl << endl;
// Client examples
// Second create() parameter set to false: no certificate verification
HttpsClient client("localhost:8080", false);
HttpsClient client("localhost:8080", false); // Second create() parameter set to false: no certificate verification
string json_string = "{\"firstName\": \"John\",\"lastName\": \"Smith\",\"age\": 25}";