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;
相关推荐
报错小能手2 分钟前
C++笔记——STL list
c++·笔记
koo3641 小时前
李宏毅机器学习笔记43
人工智能·笔记·机器学习
lkbhua莱克瓦241 小时前
Java基础——常用算法3
java·数据结构·笔记·算法·github·排序算法·学习方法
做一道光2 小时前
6、foc控制——IF控制
笔记·单片机·嵌入式硬件·电机控制
moringlightyn2 小时前
进度条+ 基础开发工具----版本控制器git 调试器gdb/cgdb
笔记·git·其他·c·调试器·gdb/cgdb·进度条 倒计时
im_AMBER2 小时前
React 15
前端·javascript·笔记·学习·react.js·前端框架
WarPigs2 小时前
Visual Studio笔记
ide·笔记·visual studio
卡提西亚2 小时前
C++笔记-24-文件读写操作
开发语言·c++·笔记
雾岛听蓝2 小时前
算法复杂度解析:时间与空间的衡量
c语言·数据结构·经验分享·笔记
yuxb733 小时前
LNMP部署及应用
笔记·云计算