TEST_F(HttpServerTest, SimpleCase) { HttpServer server; ASSERT_TRUE(server.Init("0.0.0.0", 8712)); ASSERT_TRUE(server.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(); }
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)); }
// 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); }
/*! \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; } } }
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"); }
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"); }
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(); } }
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"); }
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(); }
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; }
void web_run() { WifiStation.enable(true); server.listen(80); server.addPath("/driver/pos", web_cb_driver_pos); server.addPath("/driver/setpos", web_cb_driver_setpos); server.addPath("/driver/forward", web_cb_driver_forward); server.addPath("/driver/backward", web_cb_driver_backward); server.addPath("/driver/stop", web_cb_driver_stop); server.addPath("/scan", web_cb_start_scan); server.addPath("/scanStatus", web_cb_scan_status); server.addPath("/connect", web_cb_connect); server.setDefaultHandler(onFile); startFTP(); }
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; }
void ICACHE_FLASH_ATTR startWebServer() { server.listen(80); server.addPath("/", onIndex); server.addPath("/test", onTest); server.addPath("/ota", onOta); server.addPath("/ipconfig", onIpConfig); server.addPath("/system", onSystem); server.addPath("/ajax/get-networks", onAjaxNetworkList); server.addPath("/ajax/connect", onAjaxConnect); server.setDefaultHandler(onFile); }
void startWebServer() { server.listen(80); server.addPath("/", onIndex); server.addPath("/ipconfig", onIpConfig); server.addPath("/mqttconfig", onMqttConfig); server.addPath("/ota", onOtaConfig); server.addPath("/ajax/get-networks", onAjaxNetworkList); server.addPath("/ajax/run-ota", onAjaxRunOta); server.addPath("/ajax/connect", onAjaxConnect); server.setDefaultHandler(onFile); }
void sendUpdate(){ StaticJsonBuffer<300> sendJsonBuffer; JsonObject &json = sendJsonBuffer.createObject(); json["type"] = "state"; json["count"] = totalActiveSockets; json["time"] = SystemClock.now().toUnixTime();; json["mute"] = mute; json["source"] = source; json["mixing"] = mixing; json["enhance"] = enhance; json["volumeFR"] = 74-volumeFR; json["volumeFL"] = 74-volumeFL; json["volumeRR"] = 74-volumeRR; json["volumeRL"] = 74-volumeRL; json["volumeCEN"] = 74-volumeCEN; json["volumeSW"] = 74-volumeSW; json["frequency"] = frequency; json["volumeALLCH"] = 74-volumeALLCH; json["power"] = power; String jsonString; json.printTo(jsonString); WebSocketsList &clients = server.getActiveWebSockets(); for (int i = 0; i < clients.count(); i++){ clients[i].sendString(jsonString); } }
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(); }
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); }
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; } }
int main(int argc, char* argv[]) { server.Start(); getchar(); return EXIT_SUCCESS; }
void wsDisconnected(WebSocket& socket) { totalActiveSockets--; // Notify everybody about lost connection WebSocketsList &clients = server.getActiveWebSockets(); for (int i = 0; i < clients.count(); i++) clients[i].sendString("We lost our friend :( Total: " + String(totalActiveSockets)); }
void wsConnected(WebSocket& socket) { totalActiveSockets++; // Notify everybody about new connection WebSocketsList &clients = server.getActiveWebSockets(); for (int i = 0; i < clients.count(); i++) clients[i].sendString("New friend arrived! Total: " + String(totalActiveSockets)); }
int main(int argc, char **argv) { int port = 0; int nCPU = 0; char* rootDir = 0; int c = 0; while ((c = getopt (argc, argv, "p:n:r:")) != -1) { switch(c) { case 'p': port = atoi(optarg); if(port < 1 || port > 65535) { std::cout << "Wrong port: " << port << std::endl; return 0; } break; case 'n': nCPU = atoi(optarg); if(nCPU < 1) { std::cout << "Wrong nCPU: " << nCPU << std::endl; return 0; } break; case 'r': rootDir = optarg; if(rootDir[strlen(rootDir) - 1] == '/') { rootDir[strlen(rootDir) - 1] = '\0'; } break; } } HttpServer* httpServer = 0; try { HttpServer* httpServer = new HttpServer(); httpServer->startServer(port, nCPU, rootDir); } catch(std::exception& err) { std::cout << err.what() << std::endl; } delete httpServer; return 0; }
void readPeriodically() { Wire.beginTransmission(0x48); //talking to chip Wire.write(byte(0x00)); //status register address Wire.endTransmission(); Wire.requestFrom(0x48, 1); //request status register data int readycap; //Serial.println(" Trying read..."); //try read readycap = Wire.read(); if ((readycap & 0x1) == 0) { // ready? //Serial.print(system_get_time()); //Serial.println(" Data Ready"); //delay(10); Wire.beginTransmission(0x48); //arduino asks for data from ad7747 Wire.write(0x01); //set address point to capacitive DAC register 1 Wire.endTransmission(); //pointer is set so now we can read the //Serial.print(system_get_time()); //Serial.println(" Data Incoming"); //delay(10); Wire.requestFrom(0x48, 3,false); //reads data from cap DAC registers 1-3 while (Wire.available()) { //Serial.print(system_get_time()); //Serial.println(" Wire available."); unsigned char hi, mid, lo; //1 byte numbers long capacitance; //will be a 3byte number hi = Wire.read(); //delay(3); mid = Wire.read(); //delay(3); lo = Wire.read(); capacitance = (hi << 16) + (mid << 8) + lo - 0x800000; pf = (float) capacitance * -1 / (float) 0x800000 * 8.192f; //Serial.print(system_get_time()); //Serial.print(" "); //Serial.println(pf, DEC); //prints the capacitance data in decimal through serial port } //Serial.println(); } system_soft_wdt_feed(); char buf[22]; dtostrf(pf, 10, 8, buf); WebSocketsList &clients = server.getActiveWebSockets(); for (int i = 0; i < clients.count(); i++) { clients[i].sendString(buf); } procTimer.initializeMs(150, readPeriodically).startOnce(); }
Eina_Bool _ecore_con_handler_data_write(void *data, int type, Ecore_Con_Event_Client_Write *ev) { HttpServer *tcpserver = reinterpret_cast<HttpServer *>(data); if (ev && (tcpserver != ecore_con_server_data_get(ecore_con_client_server_get(ev->client)))) { return ECORE_CALLBACK_PASS_ON; } if (tcpserver) { tcpserver->dataWritten(ev->client, ev->size); } else { cCriticalDom("network") << "failed to get HttpServer object !"; } return ECORE_CALLBACK_RENEW; }
Eina_Bool _ecore_con_handler_client_del(void *data, int type, Ecore_Con_Event_Client_Del *ev) { HttpServer *tcpserver = reinterpret_cast<HttpServer *>(data); if (ev && (tcpserver != ecore_con_server_data_get(ecore_con_client_server_get(ev->client)))) { return ECORE_CALLBACK_PASS_ON; } if (tcpserver) { tcpserver->delConnection(ev->client); } else { cCriticalDom("network") << "failed to get HttpServer object !"; } return ECORE_CALLBACK_CANCEL; }
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); HttpPluginServer plugins{"routes.json"}; HttpServerRequestRouter router{ {QRegularExpression{""}, plugins}, {QRegularExpression{""}, HttpFileServer::handler("public")}, {QRegularExpression{""}, NotFoundHandler::handler()} }; HttpServer server; QObject::connect(&server, &HttpServer::requestReady, &router, &HttpServerRequestRouter::handleRequest); server.listen(QHostAddress::Any, 8080); return a.exec(); }
void reportEncoderPosition() { char buf[60]; char buf1[12]; floatEncoder = encoder0Pos * (2.4 / 160.0); dtostrf(floatEncoder, 4, 2, buf1); sprintf(buf, "Encoder: %s", deblank(buf1)); String message1 = String(buf); if (!message1.equals(lastPositionMessage)) { WebSocketsList &clients = server.getActiveWebSockets(); for (int i = 0; i < clients.count(); i++) { clients[i].sendString(message1); } } //printf(" * zmtp_msg: "); //zmtp_msg_t *msg = zmtp_msg_from_const_data(0, "hello", 6); //zmtp_msg_destroy(&msg); //zmtp_msg_test (false); //zmtp_channel_test (false); /* pb::Container container, got; pb::Pin *pin; pb::Value *value; // type-tag the container: container.set_type(pb::ContainerType::MT_HALUPDATE); container.set_serial(56789); container.set_rsvp(pb::ReplyType::NONE); // add repeated submessage(s) pin = container.add_pin(); pin->set_type(pb::ValueType::HAL_S32); pin->set_name("foo.1.bar"); pin->set_hals32(4711); value = container.add_value(); value->set_type(pb::ValueType::DOUBLE); value->set_v_double(3.14159); //std::string json = pb2json(container); */ }
int main(int argc, char **argv) { if(argc == 1) { // sample code to create http server HttpServer httpServer; int res = httpServer.startServer(); if (res == -1) { return res; } }else if(argc == 3){ // sample code to create http client string ip = argv[1]; int port = stoi(string(argv[2])); HttpClient httpClient(ip, port); string response = httpClient.requestToHttpServer(); cout << "Received string "<< response << endl; } return 0; }
bool ApplicationEndpointServer::buildServers () { TRI_ASSERT(_handlerFactory != nullptr); TRI_ASSERT(_applicationScheduler->scheduler() != nullptr); HttpServer* server; // unencrypted endpoints server = new HttpServer(_applicationScheduler->scheduler(), _applicationDispatcher->dispatcher(), _handlerFactory, _jobManager, _keepAliveTimeout); server->setEndpointList(&_endpointList); _servers.push_back(server); // ssl endpoints if (_endpointList.has(Endpoint::ENCRYPTION_SSL)) { // check the ssl context if (_sslContext == nullptr) { LOG_INFO("please use the --server.keyfile option"); LOG_FATAL_AND_EXIT("no ssl context is known, cannot create https server"); } // https server = new HttpsServer(_applicationScheduler->scheduler(), _applicationDispatcher->dispatcher(), _handlerFactory, _jobManager, _keepAliveTimeout, _sslContext); server->setEndpointList(&_endpointList); _servers.push_back(server); } return true; }