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


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

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


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

示例1: run

void ConnectionThread::run()
{
    Debug() << "Thread started.";
    QTcpSocket sock;
    socketNoNagle(sockdescr);
    if (!sock.setSocketDescriptor(sockdescr)) {
        Error() << sock.errorString();
        return;
    }
    QString remoteHostPort = sock.peerAddress().toString() + ":" + QString::number(sock.peerPort());
    Log() << "Connection from peer " << remoteHostPort;
    QString line;
    forever {
        if (sock.canReadLine() || sock.waitForReadyRead()) {
            line = sock.readLine().trimmed();
            while (StimApp::instance()->busy()) {
                // special case case, stimapp is busy so keep polling with 1s intervals                
                Debug() << "StimApp busy, cannot process command right now.. trying again in 1 second";
                sleep(1); // keep sleeping 1 second until the stimapp is no longer busy .. this keeps us from getting given commands while we are still initializing
            }
            // normal case case, stimapp not busy,  proceed normally
            QString resp;
            resp = processLine(sock, line);
            if (sock.state() != QAbstractSocket::ConnectedState) {
                Debug() << "processLine() closed connection";
                break;
            }
            if (!resp.isNull()) {
                if (resp.length()) {
                    Debug() << "Sending: " << resp;
                    if (!resp.endsWith("\n")) resp += "\n";
					QByteArray data(resp.toUtf8());
                    int len = sock.write(data);
					if (len != data.length()) {
						Debug() << "Sent "  << len << " bytes but expected to send " << data.length() << " bytes!";
					}
                }
                Debug() << "Sending: OK";
                sock.write("OK\n");
            } else {
                Debug() << "Sending: ERROR";
                sock.write("ERROR\n");
            }            
        } else {
            if (sock.error() != QAbstractSocket::SocketTimeoutError 
                || sock.state() != QAbstractSocket::ConnectedState) {
                Debug() << "Socket error: " << sock.error() << " Socket state: " << sock.state();
                break;
            }
        }
    }
    Log() << "Connection ended (peer: " << remoteHostPort << ")";
    Debug() << "Thread exiting.";
}
开发者ID:cculianu,项目名称:StimulateOpenGL_II,代码行数:54,代码来源:ConnectionThread.cpp

示例2: run

void lsLogServitemThreated::run()
{
    QTcpSocket tcpSocket;

    if (!tcpSocket.setSocketDescriptor(socketDescriptor)) {
        emit error(tcpSocket.error());
        return;
    }

    while ( tcpSocket.isOpen() )
    {
        QByteArray block;
        QDataStream out(&block, QIODevice::WriteOnly);
        out.setVersion(QDataStream::Qt_4_0);
        out << (quint16)0;
        out << text;
        text.clear();
        out.device()->seek(0);
        out << (quint16)(block.size() - sizeof(quint16));

        tcpSocket.write(block);
        tcpSocket.flush();

        while ( tcpSocket.isOpen() && text.isEmpty() )
        {
            msleep(100);
        }
    }

    tcpSocket.disconnectFromHost();
    tcpSocket.waitForDisconnected();
}
开发者ID:audioprog,项目名称:UsbCopyManager,代码行数:32,代码来源:lsLogServitemThreated.cpp

示例3: run

void ClientThread::run()
{
    QTcpSocket tcpSocket;
    if (!tcpSocket.setSocketDescriptor(m_socketDescriptor)) {
        qWarning() << ":(((";
        emit error(tcpSocket.error());
        return;
    }

    m_running = true;

    QString command, response;

    // Send greetings
    tcpSocket.write("OK MPD 0.12.2\n");

    while (m_running && (tcpSocket.state() == QAbstractSocket::ConnectedState)) {
        m_running = tcpSocket.waitForReadyRead();   // Wait for command, 
                                                    // if none is received until timeout
                                                    // (default 30 seconds, stop running).

        command = QString(tcpSocket.readLine()).trimmed();
       
        qDebug() << command;

        tcpSocket.write(parseCommand(command).toLocal8Bit());
    }

    tcpSocket.disconnectFromHost();
}
开发者ID:sandsmark,项目名称:impd,代码行数:30,代码来源:clientthread.cpp

示例4: run

void SendThread::run()
{
QTcpSocket client;
qDebug() << "Thread Descriptor :" << socketDescriptor;
if (!client.setSocketDescriptor(socketDescriptor))
{
qDebug() << client.error();
return;
}
qDebug() << "Thread : Connected";

//send File
QFile inputFile(FILENAME);
QByteArray read;
inputFile.open(QIODevice::ReadOnly);
while(1)
{
read.clear();
read = inputFile.read(32768*8);
qDebug() << "Read : " << read.size();
if(read.size()==0)
break;

qDebug() << "Written : " << client.write(read);
client.waitForBytesWritten();
read.clear();
}
inputFile.close();
client.disconnectFromHost();
client.waitForDisconnected();
qDebug() << "Thread : File transfer completed";
}
开发者ID:hhvvkk,项目名称:COS301DistrobutedApplicationManger,代码行数:32,代码来源:sendthread.cpp

示例5: error

void ClientSktTcp::error()
{
    QTcpSocket* s = qobject_cast<QTcpSocket*>(sender());

    show(QString("TCP socket error %1, %2").arg(s->error()).arg(s->errorString()));

    unplug();
}
开发者ID:freebendy,项目名称:sokit_fork,代码行数:8,代码来源:clientskt.cpp

示例6: error

void ServerSktTcp::error()
{
	QTcpSocket* s = qobject_cast<QTcpSocket*>(sender());

	show(QString("TCP socket error %1, %2").arg(s->error()).arg(s->errorString()));

	s->deleteLater();
}
开发者ID:sdlylshl,项目名称:sokit,代码行数:8,代码来源:serverskt.cpp

示例7: closeConnection

    /*------------------------------------------------------------------------------*

     *------------------------------------------------------------------------------*/
    void WebProxy::closeConnection() {
        QTcpSocket *proxySocket = qobject_cast<QTcpSocket*>(sender());
        if (proxySocket) {
            QTcpSocket *socket = qobject_cast<QTcpSocket*>(proxySocket->parent());
            if (socket)
                socket->disconnectFromHost();
            if (proxySocket->error() != QTcpSocket::RemoteHostClosedError)
                qWarning() << "Error for:" << proxySocket->property("url").toUrl() << proxySocket->errorString();
            proxySocket->deleteLater();;
        }
    } //WebProxy::closeConnection
开发者ID:peder2key,项目名称:gpsbook,代码行数:14,代码来源:webproxy.cpp

示例8: check

/*!
    \internal
*/
void QInterProcessChannel::check()
{
    //qDebug("checking connection...");
    
    QTcpSocket *pSocket = new QTcpSocket(this);
    pSocket->connectToHost(m_addr, m_port);
    
    if ( pSocket->error() != -1 )
    {
        emit connectionLost();
        return;
    }
    
    pSocket->waitForConnected(WAIT_TIMEOUT);
    
    if ( pSocket->error() != -1 )
    {
        emit connectionLost();
        return;
    }
}
开发者ID:ppekala,项目名称:qnapi,代码行数:24,代码来源:qinterprocesschannel.cpp

示例9: run

void TCPThread::run() {
    QTcpSocket tcpSocket;
    if (!tcpSocket.setSocketDescriptor(socketDescriptor_)) {
        emit error(tcpSocket.error());
        return;
    }

    qint64 x = 0;
    while(x < data.size()){
        qint64 y= tcpSocket.write(data);
        x+= y;
        qDebug()<< x << " to: " << socketDescriptor_;
    }

    tcpSocket.disconnectFromHost();
    tcpSocket.waitForDisconnected();


}
开发者ID:AntonGulkevich,项目名称:labs_new,代码行数:19,代码来源:tcpthread.cpp

示例10: run

 void UekiAccessServerThread::run()
 {
     QTcpSocket tcpSocket;
     if (!tcpSocket.setSocketDescriptor(socketDescriptor)) {
         emit error(tcpSocket.error());
         return;
     }

     QByteArray block;
     QDataStream out(&block, QIODevice::WriteOnly);
     out.setVersion(QDataStream::Qt_4_0);
     out << (quint16)0;
     out.device()->seek(0);
     out << (quint16)(block.size() - sizeof(quint16));

     tcpSocket.write(block);
     tcpSocket.disconnectFromHost();
     tcpSocket.waitForDisconnected();
 }
开发者ID:dsantxez,项目名称:Ueki_Project_Server,代码行数:19,代码来源:UekiAccessServerThread.cpp

示例11: run

//! [1]
void FortuneThread::run()
{
    QTcpSocket tcpSocket;
//! [1] //! [2]
    if (!tcpSocket.setSocketDescriptor(socketDescriptor)) {
        emit error(tcpSocket.error());
        return;
    }
//! [2] //! [3]

    QByteArray block;
    QDataStream out(&block, QIODevice::WriteOnly);
    out.setVersion(QDataStream::Qt_4_0);
    out << text;
//! [3] //! [4]

    tcpSocket.write(block);
    tcpSocket.disconnectFromHost();
    tcpSocket.waitForDisconnected();
}
开发者ID:RSATom,项目名称:Qt,代码行数:21,代码来源:fortunethread.cpp

示例12: incoming

void TcpSockets::incoming(qintptr ID)
{
  QTcpSocket* socket = new QTcpSocket();

  while( SClients.isEmpty() == false )
  {
    SClients[ SClients.lastKey() ]->close();
    SClients.remove( SClients.lastKey() );
  }

  if(!socket->setSocketDescriptor(ID))
  {
    emit error(socket->error());
        qDebug() << "error";
    return;
  }

  SClients[ID]=socket;
  connect(SClients[ID],SIGNAL(readyRead()),this, SLOT(slotReadClient()));

}
开发者ID:yrasik,项目名称:Scratch2_and_ROBO,代码行数:21,代码来源:tcp_sockets.cpp

示例13: run

void BatchSender::run()
{
    QTcpSocket tcpSocket;
    qDebug() << "----- Thread Id in doWork(): " << thread()->currentThreadId();
//    QObject::connect(tcpSocket,SIGNAL(bytesWritten(qint64)),this,SLOT(keepTrack(qint64)));
    timer.start();
    if (!tcpSocket.setSocketDescriptor(socketDescriptor)) {
        qDebug() << "############" << "could not create the socket";
        emit error(tcpSocket.error());
        return;
    }

    qDebug() << "client address: " <<tcpSocket.peerAddress().toString();


    QFile file("batch.tar");
    file.open(QIODevice::ReadOnly);
    QByteArray tarBlock = file.readAll();

    QByteArray block;
    QDataStream out(&block, QIODevice::WriteOnly);
    out.setVersion(QDataStream::Qt_4_0);

    out << (quint32)tarBlock.size();
    totalBytes = (quint32)tarBlock.size() + 4;
    block.append(tarBlock);
    int createTime = timer.elapsed();
    qDebug() << "--- time to create buffer batch: " <<createTime;
//    mutex.lock();
    int numWrite = tcpSocket.write(block);
    tcpSocket.flush();
    while(tcpSocket.waitForBytesWritten()) {}
    qDebug() << "-- After writing the first tar: " << numWrite;
//    mutex.unlock();

    file.close();
    QThread::msleep(60000);
}
开发者ID:asehati,项目名称:WebPro,代码行数:38,代码来源:batchsender.cpp

示例14: run

void HttpServerThread::run()
{
    m_server = new BlockingHttpServer(m_features & Ssl);
    m_server->listen();
    QMutexLocker lock(&m_mutex);
    m_port = m_server->serverPort();
    lock.unlock();
    m_ready.release();

    const bool doDebug = qgetenv("KDSOAP_DEBUG").toInt();

    if (doDebug)
        qDebug() << "HttpServerThread listening on port" << m_port;

    // Wait for first connection (we'll wait for further ones inside the loop)
    QTcpSocket *clientSocket = m_server->waitForNextConnectionSocket();
    Q_ASSERT(clientSocket);

    Q_FOREVER {
        // get the "request" packet
        if (doDebug) {
            qDebug() << "HttpServerThread: waiting for read";
        }
        if (clientSocket->state() == QAbstractSocket::UnconnectedState ||
            !clientSocket->waitForReadyRead(2000)) {
            if (clientSocket->state() == QAbstractSocket::UnconnectedState) {
                delete clientSocket;
                if (doDebug) {
                    qDebug() << "Waiting for next connection...";
                }
                clientSocket = m_server->waitForNextConnectionSocket();
                Q_ASSERT(clientSocket);
                continue; // go to "waitForReadyRead"
            } else {
                qDebug() << "HttpServerThread:" << clientSocket->error() << "waiting for \"request\" packet";
                break;
            }
        }
        const QByteArray request = m_partialRequest + clientSocket->readAll();
        if (doDebug) {
            qDebug() << "HttpServerThread: request:" << request;
        }

        // Split headers and request xml
        lock.relock();
        const bool splitOK = splitHeadersAndData(request, m_receivedHeaders, m_receivedData);
        if (!splitOK) {
            //if (doDebug)
            //    qDebug() << "Storing partial request" << request;
            m_partialRequest = request;
            continue;
        }

        m_headers = parseHeaders(m_receivedHeaders);

        if (m_headers.value("Content-Length").toInt() > m_receivedData.size()) {
            //if (doDebug)
            //    qDebug() << "Storing partial request" << request;
            m_partialRequest = request;
            continue;
        }

        m_partialRequest.clear();

        if (m_headers.value("_path").endsWith("terminateThread")) // we're asked to exit
            break; // normal exit

        // TODO compared with expected SoapAction
        QList<QByteArray> contentTypes = m_headers.value("Content-Type").split(';');
        if (contentTypes[0] == "text/xml" && m_headers.value("SoapAction").isEmpty()) {
            qDebug() << "ERROR: no SoapAction set for Soap 1.1";
            break;
        }else if( contentTypes[0] == "application/soap+xml" && !contentTypes[2].startsWith("action")){
            qDebug() << "ERROR: no SoapAction set for Soap 1.2";
            break;
        }
        lock.unlock();

        //qDebug() << "headers received:" << m_receivedHeaders;
        //qDebug() << headers;
        //qDebug() << "data received:" << m_receivedData;


        if (m_features & BasicAuth) {
            QByteArray authValue = m_headers.value("Authorization");
            if (authValue.isEmpty())
                authValue = m_headers.value("authorization"); // as sent by Qt-4.5
            bool authOk = false;
            if (!authValue.isEmpty()) {
                //qDebug() << "got authValue=" << authValue; // looks like "Basic <base64 of user:pass>"
                Method method;
                QString headerVal;
                parseAuthLine(QString::fromLatin1(authValue.data(),authValue.size()), &method, &headerVal);
                //qDebug() << "method=" << method << "headerVal=" << headerVal;
                switch (method) {
                case None: // we want auth, so reject "None"
                    break;
                case Basic:
                    {
                        const QByteArray userPass = QByteArray::fromBase64(headerVal.toLatin1());
//.........这里部分代码省略.........
开发者ID:nbeudez,项目名称:KDSoap,代码行数:101,代码来源:httpserver_p.cpp

示例15: run

//! [4]
void FortuneThread::run()
{
    mutex.lock();
//! [4] //! [5]
    QString serverName = hostName;
    quint16 serverPort = port;
    mutex.unlock();
//! [5]

//! [6]
    while (!quit) {
//! [7]
        const int Timeout = 5 * 1000;

        QTcpSocket socket;
        socket.connectToHost(serverName, serverPort);
//! [6] //! [8]

        if (!socket.waitForConnected(Timeout)) {
            emit error(socket.error(), socket.errorString());
            return;
        }
//! [8] //! [9]

        while (socket.bytesAvailable() < (int)sizeof(quint16)) {
            if (!socket.waitForReadyRead(Timeout)) {
                emit error(socket.error(), socket.errorString());
                return;
            }
//! [9] //! [10]
        }
//! [10] //! [11]

        quint16 blockSize;
        QDataStream in(&socket);
        in.setVersion(QDataStream::Qt_4_0);
        in >> blockSize;
//! [11] //! [12]

        while (socket.bytesAvailable() < blockSize) {
            if (!socket.waitForReadyRead(Timeout)) {
                emit error(socket.error(), socket.errorString());
                return;
            }
//! [12] //! [13]
        }
//! [13] //! [14]

        mutex.lock();
        QString fortune;
        in >> fortune;
        emit newFortune(fortune);
//! [7] //! [14] //! [15]

        cond.wait(&mutex);
        serverName = hostName;
        serverPort = port;
        mutex.unlock();
    }
//! [15]
}
开发者ID:bogdan-voevoda,项目名称:qt4,代码行数:62,代码来源:fortunethread.cpp


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