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


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

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


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

示例1: slt_ConnectionHandler

void HTTPServer::slt_ConnectionHandler()
{
    qDebug() << "[HTTPServer:]\tHave a new connection\n";
    QTcpSocket * socket = server.nextPendingConnection();
    socket->waitForReadyRead();
    QByteArray request(socket->readAll());
    QStringList buf = QString(request).split(' ');

    qDebug() << "Data received:\t" << buf.at(0);

    if(buf.at(0) == "POST")
    {
        QString responce = "HTTP/1.1 200 OK\r\n\r\n%1";
        socket->waitForReadyRead();
        QByteArray data(socket->readAll());
        socket->write(responce.toLatin1());
        socket->waitForBytesWritten();
        socket->disconnectFromHost();
        socket->deleteLater();

        qDebug() << "Data received: " << data;
        //--------
        //QJsonDocument doc = QJsonDocument::fromJson(data);
        //parse(doc);
    }
}
开发者ID:Aspenka,项目名称:SSD,代码行数:26,代码来源:HTTPServer.cpp

示例2: run

void ServerSwitcher::run() 
{
	QString tmp ;
	QUrl url(this->mServer + this->mRequest) ;
	QTcpSocket sock ;
	sock.connectToHost(url.host(),url.port(80));
	
	if( sock.waitForConnected() )
	{
		tmp = "GET /nowgo/%1 HTTP/1.0\r\n"
			"Host: %2\r\n"
			"User-Agent: NullGet\r\n"
			"Connection: close\r\n"
			"\r\n";
		tmp = tmp.arg(this->mRequest).arg(url.host());
		sock.write(tmp.toLatin1());
		if( sock.waitForBytesWritten() )
		{
			QByteArray ball ;
			while( sock.waitForReadyRead() )
			{
				if( ball.isEmpty())
					ball = sock.readAll();
				else
					ball += sock.readAll();
			}
			qDebug()<< ball ;
		}
	}
}
开发者ID:kitech,项目名称:karia2,代码行数:30,代码来源:serverswitcher.cpp

示例3: process

void FetchThread::process(QString phost)
{

    QUdpSocket *udpSocket ;
    udpSocket= new QUdpSocket(0);
    udpSocket->bind(QHostAddress::LocalHost, 9999);
    udpSocket->waitForConnected(250);



    QTcpSocket socket;
    socket.connectToHost("localhost", 4949);
    socket.waitForConnected(500);

    while (socket.waitForReadyRead(250));
    QString t_hello = socket.readAll();
    qDebug() << "READ: " << t_hello;

    socket.write(QString("list\n").toStdString().c_str() );
    while (socket.waitForReadyRead(250));
    QString buf1 = socket.readAll();

    qDebug() << "READ: " << buf1;
    QStringList list_probe = buf1.split(QRegExp("\\s+"));

    for (int z=0; z< list_probe.size(); z++)
    {
        QString probe=list_probe.at(z);
        QString cmd = QString("fetch ").append(probe).append("\n");
        qDebug() << "cmd : " << cmd;
        socket.write(cmd.toStdString().c_str() );


        while (socket.waitForReadyRead(250));
        QString buf2 = socket.readAll();
        qDebug() << "Rep fetch :" << buf2 << "\n";

        QRegularExpression re("(\\w+).(\\w+) ([0-9.]+)\\n");
        QRegularExpressionMatchIterator i = re.globalMatch(buf2);
        re.setPatternOptions(QRegularExpression::MultilineOption);

        while (i.hasNext()) {
            QRegularExpressionMatch match = i.next();
            QString s_metric = match.captured(1);
            QString s_value = match.captured(3);
            QString s_mtr = "monit2influxdb,metric="+probe + "_" + s_metric + ",host=" + phost+ " value=" + s_value + " " + QString::number(1000000* QDateTime::currentMSecsSinceEpoch());
            qDebug() << "metric:  " << s_mtr.toLower();

            udpSocket->writeDatagram(s_mtr.toStdString().c_str(), QHostAddress::LocalHost, 9999);




        }

        udpSocket->close();


    }
}
开发者ID:ofauchon,项目名称:monit2influxdb,代码行数:60,代码来源:fetchthread.cpp

示例4: readyRead

void TestHTTPServer::readyRead()
{
    QTcpSocket *socket = qobject_cast<QTcpSocket *>(sender());
    if (!socket || socket->state() == QTcpSocket::ClosingState)
        return;

    if (!m_directories.isEmpty()) {
        serveGET(socket, socket->readAll());
        return;
    }

    if (m_state == Failed || (m_waitData.body.isEmpty() && m_waitData.headers.count() == 0)) {
        qWarning() << "TestHTTPServer: Unexpected data" << socket->readAll();
        return;
    }

    if (m_state == AwaitingHeader) {
        QByteArray line;
        while (!(line = socket->readLine()).isEmpty()) {
            line.replace('\r', "");
            if (line.at(0) == '\n') {
                m_state = AwaitingData;
                m_data += socket->readAll();
                break;
            } else {
                if (!m_waitData.headers.contains(line)) {
                    qWarning() << "TestHTTPServer: Unexpected header:" << line
                               << "\nExpected headers: " << m_waitData.headers;
                    m_state = Failed;
                    socket->disconnectFromHost();
                    return;
                }
            }
        }
    }  else {
        m_data += socket->readAll();
    }

    if (!m_data.isEmpty() || m_waitData.body.isEmpty()) {
        if (m_waitData.body != m_data) {
            qWarning() << "TestHTTPServer: Unexpected data" << m_data << "\nExpected: " << m_waitData.body;
            m_state = Failed;
        } else {
            socket->write(m_replyData);
        }
        socket->disconnectFromHost();
    }
}
开发者ID:2gis,项目名称:2gisqt5android,代码行数:48,代码来源:testhttpserver.cpp

示例5: slotNewConnectionHandler

void MyHttpServer::slotNewConnectionHandler()
{
    qDebug() << " [ ]Have a new connection!";
    QTcpSocket* sock = m_pServer.nextPendingConnection();
    sock->waitForReadyRead();
    QByteArray request(sock->readAll());
    qDebug() << request;
    QStringList buf = QString(request).split(' ');

    if(buf.at(0) == "GET")
    {
        QString responce = "HTTP/1.1 200 OK\r\n\r\n%1";
        sock->write(responce.arg(QTime::currentTime().toString()).toLatin1());
        sock->waitForBytesWritten();
        sock->disconnectFromHost();
        sock->deleteLater();
        return;
    }

    if(buf.at(0) == "POST")
    {
	QString destUrl(buf.at(1));
        sock->waitForReadyRead();
        QByteArray data(sock->readAll());
        qDebug() << "put " << QString(data) << " into " << destUrl;
        QString responce = "HTTP/1.1 200 OK\r\n\r\n";
        sock->write(responce.toLatin1());
        sock->waitForBytesWritten();
        sock->disconnectFromHost();
        sock->deleteLater();

        //QByteArray payload;
        //payload.append(QString(data).split('=').at(1));
        //payload = QByteArray::fromBase64(QByteArray::fromPercentEncoding(payload));
        //qDebug() << payload;

        //QJsonDocument doc = QJsonDocument::fromJson(payload);
        //QJsonObject jObj = doc.object();
        //QString table = destUrl.split('/').at(2);
        //qDebug() << "table: " << table << " object: " << jObj;


        return;
    }

//    connect(sock, SIGNAL(readyRead()), this, SLOT(slotReadDataHandler()));
//    connect(sock, SIGNAL(disconnected()), this, SLOT(slotDisconnectedHandler()));
}
开发者ID:mariarti91,项目名称:testRest,代码行数:48,代码来源:MyHttpServer.cpp

示例6: frameStart

void TCPReceiveRawNode::frameStart( qint64 pTimeStamp )
{
	if( !mStream )
	{
		return;
	}

	QTcpSocket		*S = qobject_cast<QTcpSocket *>( mStream->device() );

	if( !S->isOpen() )
	{
		delete mStream;
		delete S;

		mStream = nullptr;

		return;
	}

	if( !S->bytesAvailable() )
	{
		return;
	}

	fugio::Performance	Perf( mNode, "frameStart", pTimeStamp );

	mValOutputBuffer->setVariant( S->readAll() );

	pinUpdated( mPinOutputBuffer );
}
开发者ID:Daandelange,项目名称:Fugio,代码行数:30,代码来源:tcpreceiverawnode.cpp

示例7: newRISRequest

void ListenRISRequests::newRISRequest()
{
    QTcpSocket *tcpSocket = m_tcpRISServer->nextPendingConnection();
    QString risRequestData;

    INFO_LOG("Rebuda peticio de la IP " + tcpSocket->peerAddress().toString());
    if (tcpSocket->waitForReadyRead(TimeOutToReadData))
    {
        risRequestData = QString(tcpSocket->readAll());
        INFO_LOG("Dades rebudes: " + risRequestData);
    }
    else
    {
        INFO_LOG("No s'ha rebut dades, error: " + tcpSocket->errorString());
    }

    INFO_LOG("Tanco socket");
    tcpSocket->disconnectFromHost();
    INFO_LOG("Faig delete del socket");
    delete tcpSocket;

    if (!risRequestData.isEmpty())
    {
        processRequest(risRequestData);
    }
}
开发者ID:151706061,项目名称:starviewer,代码行数:26,代码来源:listenrisrequests.cpp

示例8: clientHasData

void CTcpServer::clientHasData(QObject *obj)
{
    qDebug() << "Received client data\n";

    QTcpSocket *socket = qobject_cast<QTcpSocket *>(obj);
    emit dataReceived(socket->readAll());

#if 0
    QDataStream in(socket);
    in.setVersion(QDataStream::Qt_4_4);

    while (true)
    {
        if (clientInfo[socket] == 0)
        {
            if (socket->bytesAvailable() < (int)sizeof(quint32))
                return;

            in >> clientInfo[socket];
        }

        if (socket->bytesAvailable() < clientInfo[socket])
            return;

        clientTcpReceived(in);
        clientInfo[socket] = 0;
    }
#endif
}
开发者ID:rhelmus,项目名称:ar-rover5,代码行数:29,代码来源:tcpserver.cpp

示例9: readyRead

void Server::readyRead()
{
  QTcpSocket* socket = static_cast<QTcpSocket*>(sender());
  QByteArray* buffer = buffers.value(socket);
  qint32* s = sizes.value(socket);
  qint32 size = *s;
  while(socket->bytesAvailable() > 0) {
    buffer->append(socket->readAll());
    while((size == 0 && buffer->size() >= 4) || (size > 0 && buffer->size() >= size))
    {
      if(size == 0 && buffer->size() >= 4)
      {
        size = ArrayToInt(buffer->mid(0, 4));
        *s = size;
        buffer->remove(0, 4);
      }
      if(size > 0 && buffer->size() >= size)
      {
        QByteArray data = buffer->mid(0, size);
        buffer->remove(0, size);
        size = 0;
        *s = size;
        emit dataReceived(socket, data);
      }
    }
  }
}
开发者ID:ghostec,项目名称:White2,代码行数:27,代码来源:Server.cpp

示例10: processDeviceCommandSocket

void ServerCore::processDeviceCommandSocket()
{
	if (!serverStart)
	{
		return;
	}

	QTcpSocket *socket = deviceCmdServer->nextPendingConnection();

	QObject::connect(socket, &QTcpSocket::readyRead, [=]
	{
		QByteArray byteArray = socket->readAll();
		QJsonDocument jsonDoc = QJsonDocument::fromJson(byteArray);
		QJsonObject jsonObj = jsonDoc.object();

		QVariantMap retParamMap = prepareDataForDevice(jsonObj);
		TCP_REPLY_TYPE retType = (TCP_REPLY_TYPE)retParamMap[JSON_KEY_RETURN_TYPE].toInt();

		QString retString = JsonGenerator::GenerateJsonReply(retType, retParamMap);
		QString peerAddress = socket->peerAddress().toString();
		socket->write(retString.toLatin1());

		bool isSuccess = socket->waitForBytesWritten();

		Q_EMIT dataWrittenToDevice(peerAddress, retString);

		socket->disconnectFromHost();
	});

	QObject::connect(socket, &QTcpSocket::disconnected, [=]
	{
		socket->deleteLater();
	});
}
开发者ID:cyril0108,项目名称:samidevice,代码行数:34,代码来源:servercore.cpp

示例11: slotReadClient

void WakeServer::slotReadClient()
{
    QTcpSocket* clientSocket = (QTcpSocket*)sender();
    int idusersocs=clientSocket->socketDescriptor();
    wproto->getpacket(clientSocket->readAll());
//    QTextStream os(clientSocket);
//    os.setAutoDetectUnicode(true);
//    os << "HTTP/1.0 200 Ok\r\n"
//          "Content-Type: text/html; charset=\"utf-8\"\r\n"
//          "\r\n"
//          "<h1>WakeServer</h1>\n"
//       << QDateTime::currentDateTime().toString() << "\n";
//    qDebug() << "ReadClient:"+clientSocket->readAll()+"\n\r";
//    // Если нужно закрыть сокет
    clientSocket->close();
    SClients.remove(idusersocs);
    //    while(tcpSocket->canReadLine())
    //    {
    //        QByteArray ba = tcpSocket->readLine();
    //        if(strcmp(ba.constData(), "!exit\r\n") == 0)
    //        {
    //            tcpSocket->disconnectFromHost();
    //            break;
    //        } else {

    //        }
    //        qDebug() << ">> " << ba.constData();
    //    }
}
开发者ID:GRomR1,项目名称:libwakeproto,代码行数:29,代码来源:wakeserver.cpp

示例12: queryDeviceDisplayInfo

void ServerCore::queryDeviceDisplayInfo(QString deviceUID)
{
	QTcpSocket *socket = createSocket(deviceUID);

	QObject::connect(socket, &QTcpSocket::readyRead, [=]
	{
		QByteArray byteArray = socket->readAll();
		QJsonDocument jsonDoc = QJsonDocument::fromJson(byteArray);
		QJsonObject jsonObj = jsonDoc.object();

		if (jsonObj[JSON_KEY_STATUS].toInt() == STATUS_SUCCESSFUL)
		{
			QVariantMap retMap = jsonObj.toVariantMap();
			Q_EMIT displayInfoRecieved(deviceUID, retMap);
		}

		socket->disconnectFromHost();
	});

	QObject::connect(socket, &QTcpSocket::disconnected, [=]
	{
		socket->deleteLater();
	});

	QVariantMap paramMap;
	paramMap.insert(JSON_KEY_SEQ, 1234);

	QString jsonCmd = JsonGenerator::GenerateJsonCommand(TCP_COMMAND_TYPE::QUERY_DEVICE_DISPLAY_INFO, paramMap);

	socket->write(jsonCmd.toLatin1());
}
开发者ID:cyril0108,项目名称:samidevice,代码行数:31,代码来源:servercore.cpp

示例13: forwardRequest

/**
 * リクエストを転送する
 */
void YASWebProxy::forwardRequest()
{
    QTcpSocket* socket = qobject_cast<QTcpSocket*>(sender());
    QTcpSocket* proxySocket = socket->findChild<QTcpSocket*>("tunnel");
    QByteArray req = socket->readAll();
    proxySocket->write(req);
}
开发者ID:KoharaKazuya,项目名称:YetAnotherSecretary,代码行数:10,代码来源:yaswebproxy.cpp

示例14: run

void MessageDispatcherThread::run()
{
    QTcpSocket socket;
    socket.setSocketDescriptor(m_descriptor);
    quint64 dataSize = 0;

    while(!m_doQuit)
    {
        socket.waitForReadyRead();

        if (dataSize == 0) {
            QDataStream stream(&socket);
            stream.setVersion(QDataStream::Qt_4_6);

            if (socket.bytesAvailable() < sizeof(quint64))
                continue;

            stream >> dataSize;
        }

        if (socket.bytesAvailable() < dataSize)
            continue;

        emit gotMessage(socket.readAll(), socket.peerAddress());
        break;
    }
开发者ID:shaan7,项目名称:Kapotah,代码行数:26,代码来源:messagedispatcherthread.cpp

示例15: readyRead

void Server::readyRead()
{
	QTcpSocket * socket = static_cast<QTcpSocket *>(sender());
	QByteArray * buffer = _buffers.value(socket);
	qint32 size = *_sizes.value(socket);
	while(socket->bytesAvailable() > 0)
	{
		buffer->append(socket->readAll());
		// While can process data, process it
		while ((buffer->count() >= 4 && size == 0) || (buffer->count() >= size && size > 0))
		{
			// If size of data has received completely, then store it on global variable
			if (buffer->count() >= 4 && size == 0)
			{
				size = arrayToInt(buffer->mid(0, 4));
				buffer->remove(0, 4);
			}
			// If data has received completely
			if (buffer->count() >= size && size > 0)
			{
				QByteArray data = buffer->mid(0, size);
				buffer->remove(0, size);
				size = 0;
				processData(data, socket);
			}
		}
	}
}
开发者ID:puzzleSEQ,项目名称:server,代码行数:28,代码来源:server.cpp


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