Commit a5fcd2ba authored by Ole Christian Eidheim's avatar Ole Christian Eidheim
Browse files

Updated examples using start callback

parent d1f273a9
Loading
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -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");
+8 −7
Original line number Diff line number Diff line
@@ -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}";