#include "helloworld.h"
#include "daemontcpserver.h"
#include "fifothread.h"
#include <QFile>
#include <QtXml/QtXml>
#define OPTIONFILE "./HTTPInfo.xml"
#define OPTIONFILENAME "/HTTPInfo.xml"
HelloWorld::HelloWorld()
{
server = NULL;
InitConfig();
}
HelloWorld::~HelloWorld()
{
if (server != NULL)
{
server->close();
delete server;
}
}
void HelloWorld::InitConfig()
{
QString filePath;
QString path = QCoreApplication::applicationDirPath();
if (path.isEmpty() || path.isNull()){
filePath = OPTIONFILE;
}
else {
filePath = path + OPTIONFILENAME;
}
QFile configFile(filePath);
if (!configFile.exists())
{
return;
}
if (!configFile.open(QIODevice::ReadOnly | QFile::Text))
{
configFile.close();
return;
}
QDomDocument docConfigFile;
if (!docConfigFile.setContent(&configFile))
{
configFile.close();
return;
}
QDomElement docElem = docConfigFile.documentElement();
QDomNodeList configNodes = docElem.childNodes();
for(int i = 0; i< configNodes.length(); i++ )
{
QDomNode oneNode = configNodes.at(i);
QDomElement codeNode = oneNode.toElement();
QString xmlNameStr = codeNode.nodeName();
if (xmlNameStr == "HTTP_Port")
{
QString port = codeNode.text();
bool ok;
this->listenPort = port.toInt(&ok);
if (!ok) this->listenPort = 12345;
}
}
}
bool HelloWorld::Start()
{
server = new DaemonTcpServer(this);
connect(server, SIGNAL(newRequest(DaemonTcpRequest*, DaemonTcpResponse*)),
this, SLOT(handleRequest(DaemonTcpRequest*, DaemonTcpResponse*)));
return server->listen(QHostAddress::Any, this->listenPort);
}
void HelloWorld::handleRequest(DaemonTcpRequest *req, DaemonTcpResponse *resp)
{
//delete req
//Q_UNUSED(req);
QString data = req->GetData();
if (data != "")
{
FifoThread *write = new FifoThread(data);
connect(write, SIGNAL(finished()), write, SLOT(deleteLater()));
write->start();
//req->end();
QByteArray body = "Hello World";
resp->setHeader("Content-Length", QString::number(body.size()));
resp->writeHead(200);
resp->end(body);
}
else {
QByteArray body = "Get dirverName error";
resp->setHeader("Content-Length", QString::number(body.size()));
resp->writeHead(200);
resp->end(body);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Daemon.rar (51个子文件)
Daemon
Daemon.pro.user 24KB
daemontcpresponse.cpp 2KB
HTTPInfo.xml 90B
Daemon.pro 503B
daemontcpconnection.h 1006B
fifothread.cpp 428B
helloworld.cpp 3KB
fifo.h 402B
daemontcprequest.h 687B
.git
index 2KB
hooks
pre-push.sample 1KB
prepare-commit-msg.sample 1KB
applypatch-msg.sample 478B
pre-commit.sample 2KB
pre-applypatch.sample 424B
commit-msg.sample 896B
pre-rebase.sample 5KB
update.sample 4KB
post-update.sample 189B
config 330B
description 73B
refs
tags
heads
master 41B
remotes
origin
master 41B
HEAD 32B
logs
refs
heads
master 349B
remotes
origin
master 138B
HEAD 203B
HEAD 349B
packed-refs 107B
objects
ef
f047407908fb3902ee802bdbeb8329f7e7065e 211B
info
a5
8014740f2d04b92ce58f6ccf318a0abb5b69e6 156B
pack
pack-409989b4e28c61573ed67e5c5910d53a57be239c.pack 12KB
pack-409989b4e28c61573ed67e5c5910d53a57be239c.idx 2KB
04
7efab98b5e495b62c8d971735fe3fa6bf1cb29 714B
info
exclude 240B
COMMIT_EDITMSG 15B
HEAD 23B
fifothread.h 255B
daemontcpserver.h 714B
Daemon_NetCat.sh 244B
daemontcprequest.cpp 1011B
daemontcpserver.cpp 1KB
helloworld.h 454B
main.cpp 198B
daemontcpresponse.h 944B
header.h 909B
daemontcpconnection.cpp 2KB
qml.qrc 92B
fifo.cpp 2KB
daemonserverfw.h 189B
main.qml 146B
共 51 条
- 1
资源评论
- HisenseD2018-12-19编译错误太多
伏龙坤
- 粉丝: 9
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 穿越数学:古代智慧的AR之旅配套书籍APP-古数探秘AR
- HostelDataset(been personally processed)
- 图像分类数据:11种自然天气识别(包含训练集、验证集)
- 基于LM339芯片四路比较器模块AD09设计(原理图+PCB)工程文件.zip
- 7W1BBS86.apk
- 基于pytorch自定义卷积神经网络模型实现垃圾分类系统源码+数据集+运行说明.zip
- mmexport1714916728762.jpg
- 000.cdr
- 基于STM32F103C8+STM8S207单片机+FE8.1+CH340C设计应用开发板硬件(原理图+PCB)文件.zip
- 旅行商问题Java代码示例
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功