cpp-httplib https server not working on Linux
I am trying to create a HTTPS Server running on linux with cpp-httplib in C++. (https://github.com/yhirose/cpp-httplib) Everything worked when I used Windows. But on linux only the HTTP Server works. It seems like the HTTPS Server does not open a port which I do not understand... When typing: sudo netstat -tuplen in Terminal the expected port 8080 only shows up when running the HTTP Server not when running the HTTPS Server. My firewall also seems to be inactive: sudo ufw status gives Status: inactive
Maybe I have linked something wrong, but everything seems to run fine. I am new to C++ and Linux, so it is likely I have just made a silly mistake. I just run this code in Clion if that matters..
this is the Code for the HTTP Server (working and running as expected):
#include <iostream>
#include "./httplib.h"
int main(void) {
httplib::Server svr;
svr.Get("/hi", [](const auto&, auto& res) {
res.set_content("This is a test response", "text/plain");
});
std::cout << "start server..." << std::endl;
svr.listen("192.158.1.38", 8080);
std::cin.get();
}
this is the Code for the HTTPS Server (running but not opening a port):
#pragma comment (lib, "crypt32")
#define CPPHTTPLIB_OPENSSL_SUPPORT
#include <iostream>
#include "./httplib.h"
// These are shown by Clion that they are not used...
#include </usr/include/openssl/conf.h>
#include </usr/include/openssl/evp.h>
#include </usr/include/openssl/err.h>
int main(void) {
/// behind svr there have to be keys can not be self signed keys like in
httplib::SSLServer svr("./keys/localhost.crt", "./keys/localhost.key");
svr.Get("/hi", [](const auto&, auto& res) {
res.set_header("Access-Control-Allow-Origin", "*");
res.set_content("This is a test response", "text/plain");
});
std::cout << "start server..." << std::endl;
svr.listen("192.158.1.38", 8080);
std::cin.get();
}
My CMakeLists.txt looks like this:
cmake_minimum_required(VERSION 3.20)
project(TLS_Server)
set(CMAKE_CXX_STANDARD 17)
add_executable(TLS_Server main.cpp)
find_package(OpenSSL REQUIRED)
find_package(Threads REQUIRED)
target_link_libraries(TLS_Server PRIVATE OpenSSL::SSL PRIVATE Threads::Threads)
from Recent Questions - Stack Overflow https://ift.tt/2XVqGtz
https://ift.tt/eA8V8J
Comments
Post a Comment