Reputation: 1
ive tried out a websocket library today called uwebsockets. my code is just the one of the provided examples on their github.
int main() {
struct PerSocketData {
};
std::vector<std::thread*> threads(std::thread::hardware_concurrency());
std::transform(threads.begin(), threads.end(), threads.begin(), [](std::thread* t) {
return new std::thread([]() {
uWS::SSLApp({
/* There are example certificates in uWebSockets.js repo */
.key_file_name = "",
.cert_file_name = "",
}).ws<PerSocketData>("/*", {
/* Settings */
.compression = uWS::SHARED_COMPRESSOR,
.maxPayloadLength = 16 * 1024,
.idleTimeout = 30,
.maxBackpressure = 1 * 1024 * 1024,
/* Handlers */
.open = [](auto* ws) {
std::cout << "connected" << std::endl;
},
.message = [](auto* ws, std::string_view message, uWS::OpCode opCode) {
ws->send(message, opCode);
},
.drain = [](auto* ws) {
/* Check getBufferedAmount here */
},
.ping = [](auto* ws) {
},
.pong = [](auto* ws) {
},
.close = [](auto* ws, int code, std::string_view message) {
}
}).listen(8443, [](auto* token) {
if (token) {
std::cout << "Thread " << std::this_thread::get_id() << " listening on port " << 8443 << std::endl;
}
else {
std::cout << "Thread " << std::this_thread::get_id() << " failed to listen on port 9001" << std::endl;
}
}).run();
});
});
std::for_each(threads.begin(), threads.end(), [](std::thread* t) {
t->join();
});}
as you can see i dont supply a key directory or a cert directory, yet running this example on my server (Windows Server 2016 IIS) im able to connect to this in my browser using test sites like https://www.websocket.org/echo.html.
i thought certs are required to even get it to connect yet i get no errors and am able to connect. why is this? is this some sort of problem on my servers end?
Upvotes: 0
Views: 517
Reputation: 81
Make sure you built uWebSockets with SSL support:
make -e WITH_OPENSSL=1
By default it is built without SSL, and in this case, as far as I can tell, uWS::SSLApp works just like uWS::App. Certificate options are silently ignored.
Upvotes: 1