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;
相关推荐
依然范特东38 分钟前
强化学习笔记6--IS、PPO、TD、DQN、Actor-Critic
笔记·算法
Mxzx品牌2 小时前
佛山招聘软件哪个好:【帅聘网】匹配度高
笔记·其他·生活
九硕智慧建筑一体化厂家3 小时前
无线动能开关|烘焙后厨防潮免布线照明控制方案
运维·笔记·智慧城市
ZZHow10243 小时前
PyTorch深度学习入门笔记(小土堆)P7-14
人工智能·pytorch·笔记·python·深度学习
九硕智慧建筑一体化厂家4 小时前
直流照明|档案库房专用照明,防紫外线、防纸张老化、适配24小时值守
运维·网络·笔记·智慧城市
prog_61034 小时前
【笔记】用cursor手搓cursor(八)
笔记·llm·大语言模型·agent
一只小菜鸡..4 小时前
南京大学 操作系统 (JYY) 学习笔记:文件系统实现——从 FAT、ext2 到现代 B-Tree 黑科技
笔记·科技·学习
小飞猪。。4 小时前
笔记十八:大模型 RLHF 系统工程实战笔记
人工智能·笔记
春水碧于天,画船听雨眠5 小时前
LangChain学习笔记(一)
笔记·学习·langchain
Zzj_tju5 小时前
Instruction Tuning 论文精读路线:从 Supervised Fine-Tuning 到 Instruction Following
人工智能·笔记·学习·语言模型·自然语言处理