1 Star 0 Fork 0

木鹿/qt-server

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.cpp 1.31 KB
一键复制 编辑 原始数据 按行查看 历史
dhtesty 提交于 2024-07-08 14:07 . update
#include <iostream>
#include <QObject>
#include <QDebug>
#include <QSettings>
#include <QCoreApplication>
#include <QTcpServer>
#include <thread>
#include "wifi_iepe.h"
int main(int argc,char *argv[])
{
QCoreApplication app(argc,argv);
QSettings settings("config.ini", QSettings::IniFormat);
settings.beginGroup("tcp");
int port = settings.value("port", 9000).toInt();
settings.endGroup();
QTcpServer* server = new QTcpServer();
if(!server->listen(QHostAddress::Any,port)){
qDebug() << "Failed to start server:" << server->errorString();
return 1;
}
QObject::connect(server, &QTcpServer::newConnection, [&]() {
std::thread([&]{
QTcpSocket *clientSocket = server->nextPendingConnection();
qDebug() << "New client connected:" << clientSocket->peerAddress().toString();
IEPE_Command* command = new IEPE_Command(clientSocket);
try{
while(clientSocket->isValid()) {
command->query();
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
}catch(std::exception e){
qDebug()<<e.what();
}
clientSocket->close();
}).detach();
});
return app.exec();
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sofu456/qt-server.git
git@gitee.com:sofu456/qt-server.git
sofu456
qt-server
qt-server
master

搜索帮助