Web: support synchronous TCP/IP communication

This commit is contained in:
wmayer
2021-10-14 15:07:05 +02:00
parent a6485ad191
commit cea1216ea2
3 changed files with 29 additions and 16 deletions

View File

@@ -129,19 +129,12 @@ private:
throw Py::OverflowError("port number is lower than 0");
}
QTcpServer server;
AppServer server(true);
if (server.listen(QHostAddress(QString::fromLatin1(addr)), port)) {
bool ok = server.waitForNewConnection(timeout);
QTcpSocket* socket = server.nextPendingConnection();
if (socket) {
socket->waitForReadyRead();
if (socket->bytesAvailable()) {
QByteArray request = socket->readAll();
std::string str = AppServer::runPython(request);
socket->write(str.c_str());
socket->waitForBytesWritten();
socket->close();
}
}
server.close();