• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ WebServer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中WebServer的典型用法代码示例。如果您正苦于以下问题:C++ WebServer类的具体用法?C++ WebServer怎么用?C++ WebServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了WebServer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: startServer

void OptionWidget::startServer()
{
    WebServer* svr = WebServer::getInstance();
    svr->setDocumentRoot(_edit_rootdir->text().toStdString().c_str());
    svr->setPort(_edit_port->text().toUShort());
    svr->setEnableDirectoryListing(_cbox_dirlist->isChecked());
    svr->start();

    _btn_start->setEnabled(false);
    _btn_stop->setEnabled(true);
    _btn_restart->setEnabled(true);
}
开发者ID:384782946,项目名称:TinyHttpServer-qt,代码行数:12,代码来源:OptionWidget.cpp


示例2: main

int main(int argc, char* argv[])
{
    WebServer server;
    server.start();

    return 0;
}
开发者ID:holysoros,项目名称:Yale,代码行数:7,代码来源:main.cpp


示例3: main

int main(int argc, char *argv[])
{
  QCoreApplication app(argc, argv);

  app.setApplicationName("WebServer");
  app.setApplicationVersion("0.03");
  app.setOrganizationName("Open E-Government Project");
  app.setOrganizationDomain("open-egov.de");

  if (QCoreApplication::arguments().contains("--verbose")) {
    qDebug() << app.applicationName() << " Version " << app.applicationVersion();
    qDebug() << "Running with PID: " << getpid();
  }

  //qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));

  WebServer server;
  //http://doc.trolltech.com/4.5/qhostaddress.html
  //Null, LocalHost, LocalHostIPv6, Broadcast, and Any.
  //QHostAddress::AnyIPv6
  //QHostAddress::LocalHostIPv6
  if (! server.listen(QHostAddress::Any, 80)) {
    qDebug() << "Unable to start the server: " << server.errorString();
    return 0;
  }

  qDebug() << QObject::tr("The server is running on port %1.").arg(server.serverPort());

  return app.exec();
}
开发者ID:BackupTheBerlios,项目名称:open-egov-svn,代码行数:30,代码来源:main.cpp


示例4: web_index

/* ================================================================== *
 * Function: web_index
 * Description: Static callback function to display the homepage of the web server
 * Parameters: See Webduino documentation
 *             obj is a pointer to the instance of Server that added the callback
 * ================================================================== */
void web_index(WebServer &server, WebServer::ConnectionType type, char * c, bool b, void * obj) {
    server.httpSuccess();

    if (type != WebServer::HEAD) {
      server.printP(control_panel);
    }
}
开发者ID:SuperUser320,项目名称:muse,代码行数:13,代码来源:server.cpp


示例5: main

int main( int argc, char ** argv )
{
    QCoreApplication a(argc, argv);
    //Check whether running as root
    if( getuid() != 0){
      qDebug() << "pc-restserver must be started as root!";
      return 1;
    }
      //Setup the log file
    if(DEBUG){
      qDebug() << "pc-restserver Log File:" << logfile.fileName();
      if(QFile::exists(logfile.fileName()+".old")){ QFile::remove(logfile.fileName()+".old"); }
      if(logfile.exists()){ QFile::rename(logfile.fileName(), logfile.fileName()+".old"); }
      //Make sure the parent directory exists
      if(!QFile::exists("/var/log")){
        QDir dir;
        dir.mkpath("/var/log");
      }
      logfile.open(QIODevice::WriteOnly | QIODevice::Append);
      qInstallMessageHandler(MessageOutput);
    }
      
    //Create and start the daemon
    qDebug() << "Starting the PC-BSD REST server interface....";
    WebServer *w = new WebServer(); 
    if( w->startServer() ){
      //Now start the event loop
      QTimer::singleShot(1000, w, SLOT(stopServer()) ); //for testing purposes
      int ret = a.exec();
      logfile.close();
      return ret;
    }else{
      return 1;
    }
}
开发者ID:ownsherass,项目名称:pcbsd,代码行数:35,代码来源:main.cpp


示例6: updateShowData

void OptionWidget::updateShowData()
{
    WebServer* svr = WebServer::getInstance();

    _edit_port->setText(QString().setNum(svr->getPort()));
    _edit_rootdir->setText(QString(svr->getDocumentRoot()));
    _cbox_dirlist->setChecked(svr->isEnableDirectoryListing());
}
开发者ID:384782946,项目名称:TinyHttpServer-qt,代码行数:8,代码来源:OptionWidget.cpp


示例7: reStartServer

void OptionWidget::reStartServer()
{
    WebServer* svr = WebServer::getInstance();
    svr->reStart();
    _btn_start->setEnabled(false);
    _btn_stop->setEnabled(true);
    _btn_restart->setEnabled(true);
}
开发者ID:384782946,项目名称:TinyHttpServer-qt,代码行数:8,代码来源:OptionWidget.cpp


示例8: eventHandler

/** Static function: just call the current instance's uri handler function
 *
 *	\param networkConnection Mongoose network connection struct.
 *	\param eventCode Mongoose event code.
 *	\param dataPointer Mongoose event data, could be the http message.
 *
 */
void WebServer::eventHandler(struct mg_connection *networkConnection,
		int eventCode, void *dataPointer){
	if (eventCode == MG_EV_HTTP_REQUEST){
		WebServer* self = (WebServer *) networkConnection->user_data;
		struct http_message *httpMessage = (struct http_message *) dataPointer;

		Request request(*networkConnection, *httpMessage);
		self->handleRequest(request);
	}
}
开发者ID:fmesteban,项目名称:7552-app-server-1c2016,代码行数:17,代码来源:WebServer.cpp


示例9: main

int main(int argc, char* argv[]) {
    WebServer* server = new WebServer();

    server->port = 8181;
    server->addController("/", new IndexController());

    server->run();
    delete server;
    return 0;
}
开发者ID:MatiasNAmendola,项目名称:G3DServer,代码行数:10,代码来源:main.cpp


示例10: web_input

/* ================================================================== *
 * Function: web_input
 * Description: Static callback function to handle input to the server
 * Parameters: See Webduino documentation
 *             obj is a pointer to the instance of Server that added the callback
 * ================================================================== */
void web_input(WebServer &server, WebServer::ConnectionType type, char * c, bool b, void * obj) {
    if (type == WebServer::POST) {
        Server * s = (Server *) obj;
        bool repeat;
        char name[16], value[16];
        do {
            // Read all POST params, returns false when no more params
            repeat = server.readPOSTparam(name, 16, value, 16);

            if (strcmp(name, "visualizer") == 0) {
                int type = strtol(value, NULL, 10);
                // Ensure type is valid, default to VISUALIZER_BARS
                switch (type) {
                    case VISUALIZER_BARS:
                    case VISUALIZER_BARS_MIDDLE:
                    case VISUALIZER_PULSE:
                    case VISUALIZER_PLASMA:
                    case VISUALIZER_RAINBOW:
                    case VISUALIZER_WHEEL:
                        s->set_visualizer(type); break;
                    default:
                        s->set_visualizer(VISUALIZER_BARS); break;
                }
            } else if (strcmp(name, "other") == 0) {
                int type = strtol(value, NULL, 10);
                // Ensure type is valid, default to BOUNCING_LINES
                switch (type) {
                    case BOUNCING_LINES:
                    case BAR_TEST:
                    case PIXEL_TEST:
                    case AMBIENT_LIGHTING:
                        s->set_visualizer(type); break;
                    default:
                        s->set_visualizer(BOUNCING_LINES); break;
                }
            } else if (strcmp(name, "power") == 0) {
                s->set_power(strtol(value, NULL, 10));
            }
        } while (repeat);
            // after procesing the POST data, tell the web browser to reload
            // the page using a GET method.
            server.httpSeeOther("/web_input");
            return;
        }

        /* for a GET or HEAD, send the standard "it's all OK headers" */
        server.httpSuccess();

        /* we don't output the body for a HEAD request */
        if (type == WebServer::GET) {
            server.printP(control_panel);
        }
}
开发者ID:SuperUser320,项目名称:muse,代码行数:59,代码来源:server.cpp


示例11: main

int main(int argc, char * argv[])
{

	if(argc == 3){
		WebServer<HttpRequest> wb = WebServer<HttpRequest>("127.0.0.1", 8080, atoi( argv[1]), atoi(argv[2]) );
		wb.run();
	}
	else{
		WebServer<HttpRequest> wb = WebServer<HttpRequest>("127.0.0.1", 8080, 16, 10000);
		wb.run();
	}
}
开发者ID:prehawk1999,项目名称:lrn_webserver,代码行数:12,代码来源:main.cpp


示例12: dht

void RestDhtApi::dht(WebServer &server, WebServer::ConnectionType type,
		char *url_tail, bool tail_complete) {
	URLPARAM_RESULT rc;
	char name[32];
	char value[32];

	//server.httpSuccess("application/json");
	server.httpSuccess();

	if (type != WebServer::GET)
		return;

	if (strlen(url_tail)) {

		DHT dht;

		while (strlen(url_tail)) {

			rc = server.nextURLparam(&url_tail, name, 32, value, 32);

			String param = String(name);

			if (param == "pin") {

				String vl = value;
				int v = atoi(vl.c_str());

				dht.setup(v);

				dht.getMinimumSamplingPeriod();

				double hum = dht.getHumidity();
				double tempC = dht.getTemperature();
				double tempF = dht.toFahrenheit(tempC);

				Serial.println(v);

				Serial.print(dht.getStatusString());
				Serial.print(" - ");
				Serial.print(hum, 1);
				Serial.print("% - ");
				Serial.print(tempC, 1);
				Serial.print("C - ");
				Serial.print(tempF, 1);
				Serial.println("F");

			}

		}
	}
}
开发者ID:jpfaria,项目名称:RestDhtApi,代码行数:51,代码来源:RestDhtApi.cpp


示例13: pushButtonCmd

void WebManager::pushButtonCmd(WebServer& server, WebServer::ConnectionType type, char* url_tail, bool tail_complete) {
#ifdef PRINT_DEBUG_MSGS
	Serial.println("ajax_action");
#endif
	if (getInstance()->m_webserver->checkCredentials(IOManager::getInstance()->m_credentialsFile->m_authCredentials)) {
		if (type == WebServer::POST) {
			IOManager::getInstance()->m_actionDoorCmd->toggleFor();
		}

		/* for a GET or HEAD, send the standard "it's all OK headers" */
		server.httpSuccess();
	} else {
		/* send a 401 error back causing the web browser to prompt the user for credentials */
		server.httpUnauthorized();
	}
}
开发者ID:NicolasLambert,项目名称:GarageDoor,代码行数:16,代码来源:WebManager.cpp


示例14: defaultFailCmd

void WebServer::defaultFailCmd(WebServer &server,
                               WebServer::ConnectionType type,
                               char *url_tail,
                               bool tail_complete)
{
  server.httpFail();
}
开发者ID:SR-G,项目名称:beerduino,代码行数:7,代码来源:WebServer.cpp


示例15: CheckLogin

void CheckLogin(WebServer &rServer, WebServer::ConnectionType Type, char *pchUrlTail, bool bTailComplete)
{

  rServer.httpSuccess();

  switch (Type)
  {
  case WebServer::GET:
    SendErrorPage(rServer);
    break;

  case WebServer::POST:
    if (IsValidLogin(rServer))
    {
      ActivateGarageDoor();
      SendAccessGrantedPage(rServer);
    }
    else
      SendAccessDeniedPage(rServer);
    break;

    // None of these are expected, so we don't respond. 
  case WebServer::INVALID:
  case WebServer::HEAD:
  case WebServer::PUT:
  case WebServer::DELETE:
  case WebServer::PATCH:
  default:
    break;
  }
}
开发者ID:VaughanHunt,项目名称:GarageDoorOpener,代码行数:31,代码来源:Webserver.cpp


示例16: ShowWebRoot

// --------------- Page request handlers
void ShowWebRoot(WebServer &rServer, WebServer::ConnectionType Type, char *pchUrlTail, bool bTailComplete)
{
  // Expire grace login period when the home page is shown. 
  PasswordManager.ClearGracePassword();

  // We show the password entry page as the web root. Presents a form that asks for a password.
  rServer.httpSuccess();

  switch (Type)
  {
  case WebServer::GET:
    SendLoginPage(rServer);
    break;

  case WebServer::POST:
    SendErrorPage(rServer);
    break;

    // None of these are expected, so we don't respond. 
  case WebServer::INVALID:
  case WebServer::HEAD:
  case WebServer::PUT:
  case WebServer::DELETE:
  case WebServer::PATCH:
  default:
    break;
  }
}
开发者ID:VaughanHunt,项目名称:GarageDoorOpener,代码行数:29,代码来源:Webserver.cpp


示例17: webPageCmd

//----------------------------------------------------------------------------------------------------
// This function is called by webserver (by pointer on function). It manage http request
void WebManager::webPageCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete) {
#ifdef PRINT_DEBUG_MSGS
	Serial.println("Index");
#endif
	if (getInstance()->m_webserver->checkCredentials(IOManager::getInstance()->m_credentialsFile->m_authCredentials)) {
		/* for a GET or HEAD, send the standard "it's all OK headers" */
		server.httpSuccess();

		/* we don't output the body for a HEAD request */
		if (type != WebServer::HEAD) {
			getInstance()->m_mainPage->print();
		}
	} else {
		/* send a 401 error back causing the web browser to prompt the user for credentials */
		server.httpUnauthorized();
	}
}
开发者ID:NicolasLambert,项目名称:GarageDoor,代码行数:19,代码来源:WebManager.cpp


示例18: create_response

/**
 * Main MHD callback for handling requests.
 *
 * @param cls argument given together with the function
 *        pointer when the handler was registered with MHD
 * @param connection handle identifying the incoming connection
 * @param url the requested url
 * @param method the HTTP method used ("GET", "PUT", etc.)
 * @param version the HTTP version string (i.e. "HTTP/1.1")
 * @param upload_data the data being uploaded (excluding HEADERS,
 *        for a POST that fits into memory and that is encoded
 *        with a supported encoding, the POST data will NOT be
 *        given in upload_data and is instead available as
 *        part of MHD_get_connection_values; very large POST
 *        data *will* be made available incrementally in
 *        upload_data)
 * @param upload_data_size set initially to the size of the
 *        upload_data provided; the method must update this
 *        value to the number of bytes NOT processed;
 * @param ptr pointer that the callback can set to some
 *        address and that will be preserved by MHD for future
 *        calls for this request; since the access handler may
 *        be called many times (i.e., for a PUT/POST operation
 *        with plenty of upload data) this allows the application
 *        to easily associate some request-specific state.
 *        If necessary, this state can be cleaned up in the
 *        global "MHD_RequestCompleted" callback (which
 *        can be set with the MHD_OPTION_NOTIFY_COMPLETED).
 *        Initially, <tt>*con_cls</tt> will be NULL.
 * @return MHS_YES if the connection was handled successfully,
 *         MHS_NO if the socket must be closed due to a serios
 *         error while handling the request
 */
static int
create_response (void *cls,
                 struct MHD_Connection *connection,
                 const char *url,
                 const char *method,
                 const char *version,
                 const char *upload_data,
                 size_t *upload_data_size,
                 void **ptr)
{
    if (cls != NULL)
    {
    WebServer *server = (WebServer *)cls;
    return server->createResponse(connection, url, method, version, upload_data, upload_data_size, ptr);
    }
    
    return MHD_NO;
}
开发者ID:mrmarss,项目名称:ScareBear,代码行数:51,代码来源:WebServer.cpp


示例19: main

int main( int argc, char* argv[] )
{
	Arc_InitCore();
	Arc_InitNet();

	Log::AddInfoOutput("stdout", false);
	Log::AddErrorOutput("stderr", false);
	Log::AddInfoOutput("logs/info.log");
	Log::AddErrorOutput("logs/error.log");

	WebServer server;
	server.run();

	Log::CloseOutputs();

	Arc_TermNet();

	return 0;
}
开发者ID:WhoBrokeTheBuild,项目名称:CoeusArchive,代码行数:19,代码来源:Main.cpp


示例20: put

void RestApi::put(WebServer &server, WebServer::ConnectionType type,
		char *url_tail, bool tail_complete) {

	URLPARAM_RESULT rc;
	char name[32];
	char value[32];

	//server.httpSuccess("application/json");
	server.httpSuccess();

	if (type != WebServer::PUT)
		return;

	if (strlen(url_tail)) {
		while (strlen(url_tail)) {
			rc = server.nextURLparam(&url_tail, name, 32, value, 32);

			String param = String(name);
			String vl = value;

			int v = atoi(vl.c_str());

			if (v >= 0) {

				String t = name;
				char tp = t.charAt(0);
				String p = t.substring(1, 32);
				int pin = atoi(p.c_str());

				if (tp == 'd') {
                    digitalWrite(pin, v);
				} else {
                    analogWrite(pin, v);
                }

                Serial.print(pin + ":");
                Serial.println(v);

			}

		}
	}
}
开发者ID:jpfaria,项目名称:RestApi,代码行数:43,代码来源:RestApi.cpp



注:本文中的WebServer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ WebSocket类代码示例发布时间:2022-05-31
下一篇:
C++ WebSecurityOrigin类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap