当前位置: 首页>>代码示例>>C++>>正文


C++ QTcpSocket::peerName方法代码示例

本文整理汇总了C++中QTcpSocket::peerName方法的典型用法代码示例。如果您正苦于以下问题:C++ QTcpSocket::peerName方法的具体用法?C++ QTcpSocket::peerName怎么用?C++ QTcpSocket::peerName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QTcpSocket的用法示例。


在下文中一共展示了QTcpSocket::peerName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: slotNewConnection

void NetworkServer::slotNewConnection()
{
    QTcpSocket* socket = mTcpServer->nextPendingConnection();
    qDebug() << "NetworkServer::slotNewConnection(): accepting connection from" << socket->peerName() << "and port" << socket->peerPort();
    connect(socket, SIGNAL(disconnected()), SLOT(slotConnectionEnded()));
    connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(slotConnectionEnded()));
    connect(socket, SIGNAL(readyRead()), SLOT(slotReadSocket()));

    mTcpSockets.append(socket);
}
开发者ID:wpfhtl,项目名称:octocopter,代码行数:10,代码来源:networkserver.cpp

示例2: incomingConnection

void TvEventHandler::incomingConnection(qintptr socket)
{
    QTcpSocket* tcpSocket = new QTcpSocket(this);
    tcpSocket->setSocketDescriptor(socket);
    qCDebug(dcLgSmartTv) << "Event handler -> incoming connection" << tcpSocket->peerAddress().toString() << tcpSocket->peerName();

    connect(tcpSocket, &QTcpSocket::readyRead, this, &TvEventHandler::readClient);
    connect(tcpSocket, &QTcpSocket::disconnected, this, &TvEventHandler::onDisconnected);
}
开发者ID:defc0n1,项目名称:guh,代码行数:9,代码来源:tveventhandler.cpp

示例3: startServer

bool ZHttpServer::startServer(quint16 port)
{
    if(m_tcpServer->isListening())
        return true;

    if(!m_tcpServer->listen(QHostAddress::Any, port)){
        qWarning() << "HttpServer: error: " << m_tcpServer->errorString();
        return false;
    }else{
        qWarning() << "HttpServer: OK";
    }
    connect(m_tcpServer, &QTcpServer::newConnection, [this]{
        QTcpSocket *socket = m_tcpServer->nextPendingConnection();
        qWarning() << "HttpServer: new connect:" << socket->peerAddress().toString() << socket->peerName() << socket->peerPort();

        connect(socket, &QTcpSocket::readyRead, [socket, this]{
            HttpInfo info(socket->readAll());

            qWarning() << info.url();

            const QByteArray &query = info.url().query().toUtf8();
            QMap<QByteArray, QByteArray> command_map;

            QFileInfo fileInfo(sysroot + info.url().path());

            if (fileInfo.isFile() && fileInfo.isExecutable()) {
                execProcess((fileInfo.fileName() + " " + info.url().query(QUrl::FullyDecoded)).toLatin1(), socket);

                return;
            }

            if(!query.isEmpty()) {
                QByteArrayList commands = query.split('&');

                qWarning() << "HttpServer: command:" << commands;

                for(const QByteArray &comm : commands) {
                    if(comm.isEmpty())
                        continue;

                    const QByteArrayList &tmp_list = comm.split('=');

                    if(tmp_list.count() != 2 || tmp_list.first().isEmpty()) {
                        socket->write(messagePackage("", "text/Html", HttpInfo::BadRequest, QString("Grammatical errors: \"%1\"").arg(QString(comm))));
                        socket->close();
                        return;
                    }

                    command_map[tmp_list.first()] = tmp_list.last();
                }
            }

            if(command_map.value(ACTION) == ACTION_EXEC) {
                execProcess(QUrl::fromPercentEncoding(command_map.value(COMMAND)), socket);
            } else {
                QPointer<QTcpSocket> socket_pointer = socket;

                readFile(info.url(), socket);

                if (socket_pointer)
                    socket->close();
            }
        });
        connect(socket, &QTcpSocket::disconnected, [socket]{
            qWarning() << "HttpServer: disconnected: " << socket->peerAddress().toString() << socket->peerName() << socket->peerPort();
            socket->deleteLater();
        });
    });

    return true;
}
开发者ID:zccrs,项目名称:z-http-service,代码行数:71,代码来源:zhttpserver.cpp


注:本文中的QTcpSocket::peerName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。