12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- #include "iostream"
- #include "spdlog/spdlog.h"
- #include "printerssocketserver.h"
- PrintersSocketServer::PrintersSocketServer()
- {
- this->running = new QAtomicInteger(0);
- this->server = Q_NULLPTR;
- }
- /**
- * @brief PrintersSocketServer::setupServer
- */
- void PrintersSocketServer::setupServer()
- {
- auto console = spdlog::stdout_logger_mt("console", true);
- console->info("Welcome to spdlog");
- this->server = new QWebSocketServer(QStringLiteral("Printers Server"), QWebSocketServer::NonSecureMode);
- this->server->listen(QHostAddress("127.0.0.1"), 7800);
- if (this->server->isListening())
- {
- this->running->store(1);
- console->info("Server is listening");
- }
- }
- /**
- * @brief PrintersSocketServer::isRunning
- * @return
- */
- bool PrintersSocketServer::isRunning()
- {
- return this->running == 0;
- }
- /**
- * @brief PrintersSocketServer::stop
- */
- void PrintersSocketServer::stop()
- {
- if (!this->server->isListening()) {
- return;
- }
- while(this->server->hasPendingConnections())
- {
- const QTcpSocket &socket = this->server->nextPendingConnection();
- socket.close();
- }
- this->server->close();
- this->running->store(0);
- }
|