本文整理汇总了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);
}
示例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);
}
示例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;
}