本文整理汇总了C++中QTcpSocket::atEnd方法的典型用法代码示例。如果您正苦于以下问题:C++ QTcpSocket::atEnd方法的具体用法?C++ QTcpSocket::atEnd怎么用?C++ QTcpSocket::atEnd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTcpSocket
的用法示例。
在下文中一共展示了QTcpSocket::atEnd方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readClient
void TvEventHandler::readClient()
{
QTcpSocket* socket = (QTcpSocket*)sender();
// reject everything, except the tv
if(socket->peerAddress() != m_host){
socket->close();
socket->deleteLater();
qCWarning(dcLgSmartTv) << "Event handler -> rejecting connection from " << socket->peerAddress().toString();
return;
}
// the tv sends first the header (POST /udap/api/.... HTTP/1.1)
// in the scond package the tv sends the information (xml format)
while(!socket->atEnd()){
QByteArray data = socket->readAll();
// check if we got information
if(data.startsWith("<?xml") && m_expectingData){
m_expectingData = false;
// Answere with OK
QTextStream textStream(socket);
textStream.setAutoDetectUnicode(true);
textStream << "HTTP/1.0 200 OK\r\n"
"Content-Type: text/html; charset=\"utf-8\"\r\n"
"User-Agent: UDAP/2.0 guh\r\n"
<< "Date: " << QDateTime::currentDateTime().toString() << "\n";
emit eventOccured(data);
}
// check if we got header
if (data.startsWith("POST") && !m_expectingData) {
m_expectingData = true;
QStringList tokens = QString(data).split(QRegExp("[ \r\n][ \r\n]*"));
qCDebug(dcLgSmartTv) << "event handler -> event occured" << "http://" << m_host.toString() << ":" << m_port << tokens[1];
}
}
}