本文整理汇总了C++中WebServer类的典型用法代码示例。如果您正苦于以下问题:C++ WebServer类的具体用法?C++ WebServer怎么用?C++ WebServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WebServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例2: main
int main(int argc, char* argv[])
{
WebServer server;
server.start();
return 0;
}
示例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();
}
示例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);
}
}
示例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;
}
}
示例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());
}
示例7: reStartServer
void OptionWidget::reStartServer()
{
WebServer* svr = WebServer::getInstance();
svr->reStart();
_btn_start->setEnabled(false);
_btn_stop->setEnabled(true);
_btn_restart->setEnabled(true);
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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();
}
}
示例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");
}
}
}
}
示例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();
}
}
示例14: defaultFailCmd
void WebServer::defaultFailCmd(WebServer &server,
WebServer::ConnectionType type,
char *url_tail,
bool tail_complete)
{
server.httpFail();
}
示例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;
}
}