fixed bug with server not listening messages on first export and added a button to stop the server

This commit is contained in:
2025-03-17 22:08:38 +03:00
parent b86514b030
commit 5209b7bf22
7 changed files with 144 additions and 104 deletions

View File

@@ -21,6 +21,7 @@ OFDScene::OFDScene(QWidget *parent)
: QWidget(parent)
, ui(new Ui::OFDScene) {
ui->setupUi(this);
ui->stop_server_button->hide();
QObject::connect(this, &OFDScene::httpErrorOccured, this, &OFDScene::notifyHttpServerFailure);
}
@@ -51,6 +52,7 @@ void OFDScene::startHttpServer() {
std::string connectionString = "binaryeye://scan/?ret=http://"+ localIp +":"+ std::to_string(port) +"/?result={RESULT}";
server.Get("/", [&](const httplib::Request &req, httplib::Response &res){
std::cout << "New http connection" <<std::endl;
std::map<std::string, std::string> paramsMap;
if (req.params.size() < 1) {
res.set_redirect(connectionString, 301);
@@ -69,11 +71,13 @@ void OFDScene::startHttpServer() {
res.set_redirect(connectionString, 301);
});
std::cerr << "Listening on port: " << this->port << std::endl;
std::cout << "Listening on port: " << this->port << std::endl;
if (!server.listen("0.0.0.0", this->port)) {
std::cerr << "Random port seems to be occupied. Trying to generate another one" << std::endl;
number_of_retries ++;
continue;
} else {
break;
}
} while(true);
}
@@ -173,14 +177,17 @@ void OFDScene::on_parse_button_clicked() {
} while (!is_captcha_solved);
if (success) {
OutputDialog d = OutputDialog(this, check);
d.exec();
OutputDialog *d = new OutputDialog(this, check);
d->exec();
delete d;
}
}
void OFDScene::on_binary_eye_button_clicked() {
http_thread = new std::thread(&OFDScene::startHttpServer, this);
ui->binary_eye_button->setEnabled(false);
ui->stop_server_button->show();
while (!server.is_running());
std::string localIp;
@@ -214,3 +221,11 @@ unsigned int OFDScene::getPort() {
return port;
}
void OFDScene::on_stop_server_button_clicked() {
server.stop();
http_thread->join();
ui->stop_server_button->hide();
ui->binary_eye_button->setEnabled(true);
}