MCPcopy Create free account
hub / github.com/chronoxor/CppServer / main

Function main

examples/https_client.cpp:16–137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14#include <iostream>
15
16int main(int argc, char** argv)
17{
18 // HTTP server address
19 std::string address = "127.0.0.1";
20 if (argc > 1)
21 address = argv[1];
22 // HTTP server port
23 int port = 8443;
24 if (argc > 2)
25 port = std::atoi(argv[2]);
26
27 std::cout << "HTTPS server address: " << address << std::endl;
28 std::cout << "HTTPS server port: " << port << std::endl;
29
30 std::cout << std::endl;
31
32 // Create a new Asio service
33 auto service = std::make_shared<AsioService>();
34
35 // Start the Asio service
36 std::cout << "Asio service starting...";
37 service->Start();
38 std::cout << "Done!" << std::endl;
39
40 // Create and prepare a new SSL client context
41 auto context = std::make_shared<CppServer::Asio::SSLContext>(asio::ssl::context::tlsv13);
42 context->set_default_verify_paths();
43 context->set_root_certs();
44 context->set_verify_mode(asio::ssl::verify_peer | asio::ssl::verify_fail_if_no_peer_cert);
45 context->load_verify_file("../tools/certificates/ca.pem");
46
47 // Create a new HTTP client
48 auto client = std::make_shared<CppServer::HTTP::HTTPSClientEx>(service, context, address, port);
49
50 std::cout << "Press Enter to stop the client or '!' to reconnect the client..." << std::endl;
51
52 try
53 {
54 // Perform text input
55 std::string line;
56 while (getline(std::cin, line))
57 {
58 if (line.empty())
59 break;
60
61 // Reconnect the client
62 if (line == "!")
63 {
64 std::cout << "Client reconnecting...";
65 client->IsConnected() ? client->ReconnectAsync() : client->ConnectAsync();
66 std::cout << "Done!" << std::endl;
67 continue;
68 }
69
70 auto commands = CppCommon::StringUtils::Split(line, ' ', true);
71 if (commands.size() < 2)
72 {
73 std::cout << "HTTP method and URL must be entered!" << std::endl;

Callers

nothing calls this directly

Calls 15

set_root_certsMethod · 0.80
StartMethod · 0.45
emptyMethod · 0.45
IsConnectedMethod · 0.45
ReconnectAsyncMethod · 0.45
ConnectAsyncMethod · 0.45
sizeMethod · 0.45
getMethod · 0.45
SendHeadRequestMethod · 0.45
SendGetRequestMethod · 0.45
SendPostRequestMethod · 0.45
SendPutRequestMethod · 0.45

Tested by

no test coverage detected