c++ QTcpServer

cpp:

cpp 复制代码
   server = new QTcpServer(this);
    connect(server, &QTcpServer::newConnection, this, &PythonConsole::newConnection);
    if (!server->listen(QHostAddress::Any, 8000)) {
        qWarning("Unable to start the server: %s", qPrintable(server->errorString()));
    }

调试:

cpp 复制代码
    connect(server, &QTcpServer::newConnection, [this]() {
        QTcpSocket *socket = server->nextPendingConnection();
        qDebug() << "New connection from:" << socket->peerAddress().toString();
    });
cpp 复制代码
void PythonConsole::newConnection()
{
    clientConnection = server->nextPendingConnection();
    connect(clientConnection, &QTcpSocket::readyRead, this, &PythonConsole::readClient);
}

void PythonConsole::readClient()
{
    QByteArray data = clientConnection->readAll();
    QString command = QString::fromUtf8(data);
    runSource(command);
    clientConnection->close();
}

h:

cpp 复制代码
    QTcpServer *server;
    QTcpSocket *clientConnection;
相关推荐
Mr Sorry1 小时前
Non-stationary Diffusion For Probabilistic Time Series Forecasting论文阅读笔记
论文阅读·笔记
南猿北者1 小时前
Cmake学习笔记
笔记·学习·策略模式
码小文2 小时前
Altium Designer 22使用笔记(8)---PCB电气约束设置
笔记·嵌入式硬件·硬件工程·ad22
UserNamezhangxi5 小时前
kotlin 协程笔记
java·笔记·kotlin·协程
翻滚的小@强8 小时前
数据挖掘笔记:点到线段的距离计算
人工智能·笔记·数据挖掘
会思考的猴子8 小时前
UE5 PCG 笔记(二) Difference 节点
笔记·ue5
yuxb738 小时前
Linux 文本处理与 Shell 编程笔记:正则表达式、sed、awk 与变量脚本
linux·笔记·正则表达式
饕餮争锋11 小时前
设计模式笔记_行为型_访问者模式
笔记·设计模式·访问者模式
不羁。。13 小时前
【撸靶笔记】第七关:GET - Dump into outfile - String
数据库·笔记·oracle
好望角雾眠18 小时前
第一阶段C#基础-10:集合(Arraylist,list,Dictionary等)
笔记·学习·c#