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;
相关推荐
摇滚侠21 分钟前
Spring Boot3零基础教程,Profile 环境隔离用法,笔记55
java·spring boot·笔记
新子y31 分钟前
【小白笔记】input() 和 print() 这两个函数
笔记·python
雾岛听蓝39 分钟前
C语言:使用顺序表实现通讯录
c语言·数据结构·经验分享·笔记·visualstudio
于顾而言3 小时前
【笔记】Comprehensive Rust语言学习
笔记·学习·rust
芥子沫4 小时前
Docker安装思源笔记&使用指南
笔记·docker·容器·思源笔记
递归不收敛4 小时前
三、检索增强生成(RAG)技术体系
人工智能·笔记·自然语言处理
im_AMBER4 小时前
React 06
前端·javascript·笔记·学习·react.js·前端框架
autism_cx5 小时前
TCP/IP协议栈
服务器·网络·笔记·网络协议·tcp/ip·ios·osi
报错小能手5 小时前
C++笔记(面向对象)对于对象返回方式的讲解
笔记
Olrookie5 小时前
StreamX部署详细步骤
大数据·笔记·flink