本文整理汇总了C++中HttpServer类的典型用法代码示例。如果您正苦于以下问题:C++ HttpServer类的具体用法?C++ HttpServer怎么用?C++ HttpServer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HttpServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TEST_F
TEST_F(HttpServerTest, SimpleCase) {
HttpServer server;
ASSERT_TRUE(server.Init("0.0.0.0", 8712));
ASSERT_TRUE(server.Start());
}
示例2: start
int HttpServer::start()
{
HttpServer* svr = HttpServer::getInstance();
QString ip = svr->m_GlobalConfig["bindIp"].toString("0.0.0.0").trimmed();
auto port = svr->m_GlobalConfig["bindPort"].toInt(8080);
auto callback = [svr](QttpRequest& req, QttpResponse& resp) {
HttpEvent* event = new HttpEvent(&req, &resp);
QCoreApplication::postEvent(svr, event);
};
native::http::Qttp server;
auto result = server.listen(ip.toStdString(), port, callback);
if(!result)
{
LOG_ERROR("Unable to bind to" << ip << ":" << port);
if(svr->m_ServerErrorCallback)
{
svr->m_ServerErrorCallback();
}
LOG_FATAL(ip << ":" << port << " " << SERVER_ERROR_MSG);
return 1;
}
LOG_INFO("Server pid" << QCoreApplication::applicationPid() <<
"running at" << ip << port);
return native::run();
}
示例3: main
int main(int, char**)
{
HttpServer server;
server.start();
server.setSink(&handler);
server.bind("localhost", {"server.crt", "server.key", "", "", "", ""}, "8080");
while (true)
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
示例4: hc_process
/*! \brief Process an incoming message */
static void hc_process(HttpConnection* connection) {
const char* tmp;
const char* data;
int content_size, header_size;
HttpRequest hr;
HttpServer* server = connection->server;
/* get the content lenght */
tmp = http_get_field(connection->header, "Content-Length");
if(tmp == NULL) {
content_size = 0;
} else {
content_size = atoi(tmp);
}
/* find the beginning of the content */
data = strstr(connection->buffer, HTTP_LINE_SEP HTTP_LINE_SEP) + 4;
header_size = data - connection->buffer;
/* check if the message is bigger than current buffer size */
if(content_size + header_size >= MAX_BUFFER_SIZE) {
log(WARNING, "Message is too big");
hc_report_error(connection, "Message is too big");
return;
}
/* check if everything is here */
if(connection->buffer_size >= header_size + content_size) {
log(INFO, "Processing request Content-Length=%d", content_size);
/* inform the request */
hr.connection = connection;
hr.header = connection->header;
hr.data = data;
hr.data_size = content_size;
server->callback(server->user_data, &hr);
/* free the header, we don't need it anymore */
http_delete(connection->header);
connection->header = NULL;
/* move the buffer */
if(connection->buffer_size > header_size + content_size) {
memmove(connection->buffer, connection->buffer + header_size +
content_size, connection->buffer_size - header_size -
content_size);
connection->buffer_size -= header_size + content_size;
} else {
connection->buffer_size = 0;
}
}
}
示例5: main
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QCoreApplication app(argc, argv);
QCoreApplication::setApplicationName("evnav-cli");
QCoreApplication::setApplicationVersion("0.1");
QCommandLineParser parser;
parser.setApplicationDescription("electric vehicule trip planner");
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument("osrm", "path to osrm file");
parser.addPositionalArgument("charger", "path to json charger file");
parser.process(app);
const QStringList args = parser.positionalArguments();
if (args.size() < 2) {
qDebug() << "missing arguments";
parser.showHelp(1);
}
qDebug() << "loading street data...";
Evnav evnav(args.at(0));
qDebug() << "loading chargers...";
ChargerProvider provider;
provider.loadJson(args.at(1));
ChargerProvider dcfc = provider.filter(provider.fastChargerFilter());
qDebug() << "fast chargers found:" << dcfc.size();
evnav.setChargerProvider(&dcfc);
evnav.initGraph();
HttpServer httpd;
EvnavServer handler;
handler.setEngine(&evnav);
HttpServerRequestRouter router {
{ QRegularExpression{"^/route/v1/evnav/.*"}, handler },
{ QRegularExpression{",*"}, NotFoundHandler::handler() },
};
QObject::connect(&httpd, &HttpServer::requestReady,
&router, &HttpServerRequestRouter::handleRequest);
httpd.listen(QHostAddress::Any, 8080);
return a.exec();
}
示例6: main
int main()
{
apr_pool_t* mempool;
apr_initialize();
apr_pool_create(&mempool, NULL);
apr_atomic_init(mempool);
apr_sockaddr_t* sockaddr;
apr_sockaddr_info_get(&sockaddr, "127.0.0.1", APR_INET, 8080, 0, mempool);
HttpServer* hs = new HttpServer(100, FRL_LOCK_FREE, mempool);
hs->spawn(5, 10, sockaddr);
hs->wait();
apr_terminate();
return 0;
}
示例7: stringify
int HealthCheckTestHelper::execute()
{
os::setenv("LIBPROCESS_IP", flags.ip);
os::setenv("LIBPROCESS_PORT", stringify(flags.port));
HttpServer* server = new HttpServer();
process::spawn(server);
process::wait(server->self());
delete server;
return EXIT_SUCCESS;
}
示例8: main
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
HttpServer server;
QObject::connect(&server, &HttpServer::requestReady,
[](HttpServerRequest &, HttpServerResponse &res){
res.writeHead(HttpResponseStatus::OK);
res.end("Hello World");
});
server.listen(QHostAddress::Any, 8080);
return a.exec();
}
示例9: initTestCase
void MonkeyTest::initTestCase()
{
HttpServer* httpSvr = TestUtils::setUp(this);
QVERIFY(httpSvr != nullptr);
QVERIFY(httpSvr->initialize() == true);
auto action = httpSvr->createAction([](HttpData& data) {
QJsonObject& json = data.getResponse().getJson();
json["response"] = "C++ FTW";
});
action->registerRoute(HttpMethod::GET, "something");
httpSvr->startServer("127.0.0.1", 8080);
QTest::qWait(1000);
}
示例10: CtrlHandler
BOOL CtrlHandler(DWORD fdwCtrlType)
{
HttpServer* server;
switch (fdwCtrlType)
{
// Handle the CTRL-C signal.
case CTRL_C_EVENT:
LOG(INFO) << "The user wants to close server.";
// shutdown server
server = (HttpServer*)MainObjectFactoryImpl::getInstance()->getObject("HttpServer");
if (server != NULL){
server->stop();
}
else{
LOG(WARNING) << "Failed to get server instance from factory.";
}
return(TRUE);
// CTRL-CLOSE: confirm that the user wants to exit.
//case CTRL_CLOSE_EVENT:
// // shutdown server
// if (server != NULL){
// server->stop();
// }
// return(TRUE);
// // Pass other signals to the next handler.
//case CTRL_BREAK_EVENT:
// Beep(900, 200);
// printf("Ctrl-Break event\n\n");
// return FALSE;
//case CTRL_LOGOFF_EVENT:
// Beep(1000, 200);
// printf("Ctrl-Logoff event\n\n");
// return FALSE;
//case CTRL_SHUTDOWN_EVENT:
// Beep(750, 500);
// printf("Ctrl-Shutdown event\n\n");
// return FALSE;
default:
return FALSE;
}
}
示例11: startWebServer
// Will be called when system initialization was completed
void startWebServer()
{
Serial.println("starting web-server...");
server.listen(80);
server.addPath("/ajax/get-networks", onAjaxNetworkList);
server.addPath("/ajax/connect", onAjaxConnect);
server.addPath("/ajax/get-ip", onAjaxGetIP);
server.addPath("/ajax/disable-ap", onAjaxDisableAP);
}
示例12: StartServers
void StartServers()
{
server.listen(80);
server.addPath("/", onIndex);
server.setDefaultHandler(onFile);
// Web Sockets configuration
server.enableWebSockets(true);
server.commandProcessing(true,"command");
server.setWebSocketConnectionHandler(wsConnected);
server.setWebSocketMessageHandler(wsMessageReceived);
server.setWebSocketBinaryHandler(wsBinaryReceived);
server.setWebSocketDisconnectionHandler(wsDisconnected);
Serial.println("\r\n=== WEB SERVER STARTED ===");
Serial.println(WifiStation.getIP());
Serial.println("==============================\r\n");
// Start FTP server
ftp.listen(21);
ftp.addUser("me", "123"); // FTP account
Serial.println("\r\n=== FTP SERVER STARTED ===");
Serial.println("==============================\r\n");
telnet.listen(23);
telnet.enableDebug(true);
Serial.println("\r\n=== TelnetServer SERVER STARTED ===");
Serial.println("==============================\r\n");
}
示例13: startWebServer
void startWebServer()
{
server.listen(80);
server.addPath("/", onIndex);
server.addPath("/hello", onHello);
server.setDefaultHandler(onFile);
Serial.println("\r\n=== WEB SERVER STARTED ===");
Serial.println(WifiStation.getIP());
Serial.println("==============================\r\n");
}
示例14: GetTickCount
void CP2PServiceModule::OnCheckTimer( UINT uID, UINT uTime )
{
if ( !g_socketClientMgr.IsConnected())
{
CKLog::WriteLog( LOG_TYPE_DEBUG, "reconnect server.%d", GetTickCount());
g_server.stop();
g_socketClientMgr.Release();
if ( g_socketClientMgr.Connect())
g_server.start();
}
}
示例15: startWebServer
void startWebServer()
{
server.listen(80);
server.addPath("/", onIndex);
server.addPath("/ajax/input", onAjaxInput);
server.addPath("/ajax/frequency", onAjaxFrequency);
server.setDefaultHandler(onFile);
Serial.println("\r\n=== WEB SERVER STARTED ===");
Serial.println(WifiStation.getIP());
Serial.println("==============================\r\n");
}