Files
uWebSockets/main.cpp
T
2018-06-25 00:21:16 +02:00

44 lines
1.1 KiB
C++

#include "uWS.h"
std::string buffer;
//#define USE_SSL
int main(int argc, char **argv) {
// dynamically set respinse size from arguments
if (argc == 2) {
int bytes = atoi(argv[1]);
std::cout << "Server going to respond with " << bytes << " bytes of data" << std::endl;
buffer.resize(bytes);
} else {
std::cout << "Usage: uWS_test bytesInResponse" << std::endl;
return -1;
}
//uWS::init();
//uWS::Loop loop();
#ifdef USE_SSL
uWS::SSLApp app(uWS::SSLOptions()
.keyFileName("/home/alexhultman/uWebSockets/misc/ssl/key.pem")
.certFileName("/home/alexhultman/uWebSockets/misc/ssl/cert.pem")
.passphrase("1234"));
#else
uWS::App app;
#endif
app.onGet("/", [](auto *s, auto *req, auto *args) {
s->writeStatus("200 OK")->write([](int offset) {
return std::string_view(buffer.data() + offset, buffer.length() - offset);
}, buffer.length());
}).onWebSocket("/wsApi", []() {
}).listen("localhost", 3000, 0);
uWS::run();
// loop.run();
}