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


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

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


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

示例1: connectToHost

bool ImapPrivate::connectToHost (const QString& host, quint16 port, bool useSsl)
{
#ifndef QT_NO_OPENSSL
    if (useSsl)
        socket = new QSslSocket;       
    else
        socket = new QTcpSocket;
#else
    Q_UNUSED(useSsl)
    socket = new QTcpSocket;
#endif

#ifndef QT_NO_OPENSSL
    if (useSsl) {
        QSslSocket *sslSocket = static_cast<QSslSocket *>(socket);
        sslSocket->connectToHostEncrypted(host, port);
        return(sslSocket->waitForEncrypted());
    } else {
        socket->connectToHost(host, port);
        return(socket->waitForConnected());
    }
#else
    socket->connectToHost(host, port);
    return(socket->waitForConnected());
#endif
}
开发者ID:vohulg,项目名称:newimapgui,代码行数:26,代码来源:imap.cpp

示例2: connectOne

void ConnectTrd::connectOne(QString ip)
{
    QTcpSocket *socket = new QTcpSocket();

    connect(socket,SIGNAL(readyRead()),this,SLOT(canRead()));


    socket->connectToHost("192.168.1.240",AKHMI_PORT);

    socket->waitForConnected();

    qDebug()<< socket->waitForConnected()<< socket->errorString();
}
开发者ID:maqiangddb,项目名称:pc_code,代码行数:13,代码来源:connecttrd.cpp

示例3: internetStatus

//-----------------------------------------------------------------------------
void
QGCCacheWorker::_testInternet()
{
    /*
        To test if you have Internet connection, the code tests a connection to
        8.8.8.8:53 (google DNS). It appears that some routers are now blocking TCP
        connections to port 53. So instead, we use a TCP connection to "github.com"
        (80). On exit, if the look up for “github.com” is under way, a call to abort
        the lookup is made. This abort call on Android has no effect, and the code
        blocks for a full minute. So to work around the issue, we continue a direct
        TCP connection to 8.8.8.8:53 on Android and do the lookup/connect on the
        other platforms.
    */
#if defined(__android__)
    QTcpSocket socket;
    socket.connectToHost("8.8.8.8", 53);
    if (socket.waitForConnected(2000)) {
        qCDebug(QGCTileCacheLog) << "Yes Internet Access";
        emit internetStatus(true);
        return;
    }
    qWarning() << "No Internet Access";
    emit internetStatus(false);
#else
    if(!_hostLookupID) {
        _hostLookupID = QHostInfo::lookupHost("www.github.com", this, SLOT(_lookupReady(QHostInfo)));
    }
#endif
}
开发者ID:JcZou,项目名称:qgroundcontrol,代码行数:30,代码来源:QGCTileCacheWorker.cpp

示例4: connectToMaster

void ProtoConnect::connectToMaster(QString ipAddress, int serverPort, ProtocolHandler * protocolHandler){

    QTcpSocket *socket = new QTcpSocket(this);

    //making sure it is disconnectedclose();

    socket->connectToHost(ipAddress, serverPort);

    //wait for one second for connection
    if(!socket->waitForConnected(1000)){
        //error
        qDebug()<<"Error when connecting";
        return;
    }

    SocketClient *socketClient = new SocketClient(protocolHandler, socket);

    //connect(socket, SIGNAL(connected()), socketClient, SLOT(connected()));
    connect(socket, SIGNAL(readyRead()), socketClient, SLOT(readyRead()));
    connect(socket, SIGNAL(disconnected()), socketClient, SLOT(disconnected()));

    //write to the server to connect
    socket->write("||Hello AppMan||");
    socket->flush();

    //finally set the socket so that the network can use it
    protocolHandler->setSocket(socket);
}
开发者ID:hhvvkk,项目名称:COS301DistrobutedApplicationManger,代码行数:28,代码来源:protoconnect.cpp

示例5: 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

示例6: run

void ThreadJoueurs::run()
{
    QTcpSocket unSocket;


    unSocket.setSocketDescriptor(m_socketDescriptor);
    if(unSocket.waitForConnected(1000))
    {
        while(unSocket.ConnectedState)         //.waitForReadyRead(1000))
        {
            baRXInfos=unSocket.read(unSocket.bytesAvailable());
            if(baRXInfos.left(1) == "&")    //code de connection des joueurs
            {
                unSocket.write(baTXInfos.append(cNoJ));     //assignation du numero
                baTXInfos = TXInfosToJoueurs(m_tNouvellePartie,9);  // trame de debut de partie (= NouvellePartie)
            }
            else
            {
                RXInfosFmJoueurs(baRXInfos);                //recoit {'#', JnX, JnY}
                baTXInfos = TXInfosToJoueurs(m_txInfos,9);  //repond trame {code, balle X, balle Y, J1X, J1Y, J2X, J2Y, ScoreA, ScoreB}
            }                                               // code = '#' (normale), '$' (gagnant), '%' (Nouvelle Balle)
            unSocket.write(baTXInfos);
            unSocket.waitForBytesWritten(10);
        }
    }
    unSocket.disconnectFromHost();
    unSocket.close();

}
开发者ID:Sassinak,项目名称:cll12-Pong,代码行数:29,代码来源:threadjoueurs.cpp

示例7: kDebug

NavigationWidget::NavigationWidget(KDevelop::DeclarationPointer declaration, KDevelop::TopDUContextPointer topContext, const QString& /* htmlPrefix */, const QString& /* htmlSuffix */)
{
    kDebug() << "Navigation widget for Declaration requested";
    m_topContext = topContext;
    
    initBrowser(400);
    
    DeclarationNavigationContext* context = new DeclarationNavigationContext(declaration, m_topContext);
    m_startContext = context;
    setContext(m_startContext);
    
    m_fullyQualifiedModuleIdentifier = context->m_fullyQualifiedModuleIdentifier;
    kDebug() << "Identifier: " << m_fullyQualifiedModuleIdentifier;
    if ( m_fullyQualifiedModuleIdentifier.length() ) {
        kDebug() << "Checking wether doc server is running";
        QTcpSocket* sock = new QTcpSocket();
        sock->connectToHost(QHostAddress::LocalHost, 1050, QTcpSocket::ReadOnly);
        bool running = sock->waitForConnected(300);
        if ( ! running ) {
            kDebug() << "Not running, starting pydoc server";
            QProcess::startDetached("/usr/bin/env", QStringList() << "python" << QString(INSTALL_PATH) + "/pydoc.py" << "-p" << "1050");
            usleep(100000); // give pydoc server 100ms to start up
        }
        else {
            sock->disconnectFromHost();
        }
        delete sock;
        
        m_documentationWebView = new QWebView(this);
        m_documentationWebView->load(QUrl("http://localhost:1050/" + m_fullyQualifiedModuleIdentifier + ".html"));
        connect( m_documentationWebView, SIGNAL(loadFinished(bool)), SLOT(addDocumentationData(bool)) );
    }
}
开发者ID:mcanes,项目名称:kdevelop-python,代码行数:33,代码来源:navigationwidget.cpp

示例8: run

void mjpegThread::run()
{
    QTcpSocket *socket = new QTcpSocket(this);

    connect(socket, SIGNAL(connected()),this, SLOT(connected()));
    connect(socket, SIGNAL(disconnected()),this, SLOT(disconnected()));
    connect(socket, SIGNAL(readyRead()),this, SLOT(readyRead()));
    
    QUrl url(cfg->get("src1/url"), QUrl::TolerantMode);

    socket->connectToHost(url.host(), 80);

    if(!socket->waitForConnected(5000))
    {
      qDebug() << "Error: " << socket->errorString();
    }


    while (fRun)
    {
        sleep(1);
    }

    socket->close();
}
开发者ID:alex43dm,项目名称:mjpeg-qt,代码行数:25,代码来源:mjpegthread.cpp

示例9: SendData

bool Server::SendData(QHostAddress ip_to, QString message)
{
    bool result = false;
    QTcpSocket* tcpSocket = sockets->value(ip_to.toIPv4Address(), 0);
    if (tcpSocket && tcpSocket->state()==QAbstractSocket::ConnectedState && tcpSocket->isWritable()) {
        emit write_message(tr("Sending data (size=%1) to %2. Content: \"%3\"").arg(message.length()).arg(ip_to.toString()).arg(message));
        tcpSocket->write(message.toUtf8());
        result = tcpSocket->waitForBytesWritten();
    } else {
        tcpSocket = new QTcpSocket();
        tcpSocket->connectToHost(ip_to, remote_port, QIODevice::ReadWrite);
        tcpSocket->waitForConnected(5000);

        if (tcpSocket->state()==QAbstractSocket::ConnectedState) {
            emit write_message(tr("Sending data (size=%1) from new socket to %2. Content: \"%3\"").arg(message.length()).arg(ip_to.toString()).arg(message));
            tcpSocket->write(message.toUtf8());
            result = tcpSocket->waitForBytesWritten(5000);
        } else {
            emit error(tr("Client \"%1\" not found").arg(ip_to.toString()));
        }

        tcpSocket->abort();
        delete tcpSocket;
    }
    return result;
}
开发者ID:bukmare,项目名称:ESP_CStation,代码行数:26,代码来源:server.cpp

示例10: defined

//----------------------------------------------------------------------------------
void tst_QTcpServer::ipv6Server()
{
#if defined(Q_OS_SYMBIAN)
    QSKIP("Symbian: IPv6 is not yet supported", SkipAll);
#endif
    //### need to enter the event loop for the server to get the connection ?? ( windows)
    QTcpServer server;
    if (!server.listen(QHostAddress::LocalHostIPv6, 8944)) {
        QVERIFY(server.serverError() == QAbstractSocket::UnsupportedSocketOperationError);
        return;
    }

    QVERIFY(server.serverPort() == 8944);
    QVERIFY(server.serverAddress() == QHostAddress::LocalHostIPv6);

    QTcpSocket client;
    client.connectToHost("::1", 8944);
    QVERIFY(client.waitForConnected(5000));

    QVERIFY(server.waitForNewConnection());
    QVERIFY(server.hasPendingConnections());

    QTcpSocket *serverSocket = 0;
    QVERIFY((serverSocket = server.nextPendingConnection()));
}
开发者ID:husninazer,项目名称:qt,代码行数:26,代码来源:tst_qtcpserver.cpp

示例11: write

void server::write(QString value)
{
    QTcpSocket *client = Server->nextPendingConnection();

    if (client->waitForConnected(3000))
    {
        qDebug() << "Client Connected: ...";

        client->write("The connection is sucessfull");

        client->waitForBytesWritten(1000);
        client->waitForReadyRead(3000);

        qDebug() << "Reading" << client->bytesAvailable();

        qDebug() << client->readAll();

        client->close();
    }

    else
    {
        qDebug() << "Connection Failed...";
    }
}
开发者ID:arjunpassi,项目名称:Battleship---Final-Project,代码行数:25,代码来源:server.cpp

示例12: refreshGames

void NewGame::refreshGames()
{
    this->ui->listRefresh->setEnabled(false);
    this->ui->listGame->clear();
    unsigned int ip;
    unsigned int netmask = 0xffffff00;
    foreach (QNetworkInterface it, QNetworkInterface::allInterfaces())
        foreach (QHostAddress addr, it.allAddresses())
            if (addr.toIPv4Address() && 0xff000000 != 0x7f000000)
                ip = addr.toIPv4Address();
    unsigned int networkaddr = ip & netmask;
    for (unsigned int i = 1; i < 256; i++)
    {
        unsigned int currentIp = networkaddr + i;
        QTcpSocket* s = new QTcpSocket();
        s->connectToHost(QHostAddress(currentIp), 1338);
        static_cast<MainWindow*>(this->parent())->print_status("Scanning ...\tCurrent : " + QHostAddress(currentIp).toString());
        if (s->waitForConnected(5))
        {
            this->ui->listGame->addItem(new QListWidgetItem(QHostAddress(currentIp).toString()));
            QCoreApplication::processEvents();
            // tell the slave this is just a search request
            s->write("s", 1);
            s->close();
        }
    }
    static_cast<MainWindow*>(this->parent())->print_status("End of scan");
    this->ui->listRefresh->setEnabled(true);
}
开发者ID:Surogate,项目名称:gomhokuto-de-cuisine,代码行数:29,代码来源:newgame.cpp

示例13: sendBase

void MT500::testConnection()
{
    for(int i = 0; i < 6; i++) {
        if(!ipArray[i].ip.isEmpty()){
            QString msg = "[" + QDateTime::currentDateTime().toString("MM/dd/yyyy hh:mm:ss") + "] ";
            QTcpSocket * test = new QTcpSocket;
            test->connectToHost(QHostAddress(ipArray[i].ip), ipArray[i].port);
            if(test->waitForConnected(2000)) {
                msg += ipArray[i].ip + ": Test Message Sent";
                ui->testBrowser->append("<font color=green>" + msg + "</font>");
                test->abort();
            }
            else {
                msg += ipArray[i].ip + ": Failed to Connect";
                ui->testBrowser->append("<font color=red>" + msg + "</font>");
            }
        }
    }
    if(!initial) {
        QString fips = fipsNo.trimmed().remove("VAZ");
        QString msgToSend = "A 100 " + QDateTime::currentDateTime().toString("MM/dd/yyyy hh:mm:ss") + " " + QString::number(boxGID);
        sendBase(msgToSend, true);
        sendRaw(msgToSend);
        sendRawStrtoIflows(QString(encode(msgToSend)));
    }
    else initial = false;
}
开发者ID:mtech12,项目名称:MT500,代码行数:27,代码来源:mt500.cpp

示例14: getSensorTemperature

int MainWindow::getSensorTemperature(){
   // Get the server address and port from the settings dialog box
   int serverPort = this->dialog->getServerPort();  // get from the dialog box
   quint32 serverAddr = this->dialog->getIPAddress();   // from the dialog box
   QTcpSocket *tcpSocket = new QTcpSocket(this);    // create socket
   tcpSocket->connectToHost(QHostAddress(serverAddr), serverPort); // connect
   if(!tcpSocket->waitForConnected(1000)){    //wait up to 1s for a connection
      statusBar()->showMessage("Failed to connect to server...");
      return 1;
   }
   // Send the message "getTemperature" to the server
   tcpSocket->write("getTemperature");
   if(!tcpSocket->waitForReadyRead(1000)){    // wait up to 1s for the server
      statusBar()->showMessage("Server did not respond...");
      return 1;
   }
   // If the server has sent bytes back to the client
   if(tcpSocket->bytesAvailable()>0){
      int size = tcpSocket->bytesAvailable(); // how many bytes are ready?
      char data[20];                          // upper limit of 20 chars
      tcpSocket->read(&data[0],(qint64)size); // read the number of bytes rec.
      data[size]='\0';                        // termintate the string
      this->curTemperature = atof(data);      // string -> float conversion
      cout << "Received the data [" << this->curTemperature << "]" << endl;
   }
   else{
      statusBar()->showMessage("No data available...");
   }
   return 0;    // the on_updateTemperature() slot will update the display
}
开发者ID:19Dan01,项目名称:exploringBB,代码行数:30,代码来源:mainwindow.cpp

示例15: send

bool Http::send(QString host, int port, QByteArray data, QByteArray &result, int timeout)
{
    QByteArray response;
    QTcpSocket socket;
    int numRead = 0;
    int numReadTotal = 0;
    char buffer[50];

    socket.connectToHost(QHostAddress(host),port);
    if (!socket.waitForConnected(timeout)) {
        return false;
    }

    socket.write(data);
    if (!socket.waitForBytesWritten(timeout))
    {
        return false;
    }

    forever {
        numRead  = socket.read(buffer, 50);
        numReadTotal += numRead;
        response.append(buffer,numRead);
        if (numRead == 0 && !socket.waitForReadyRead(timeout))
            break;
    }
    socket.disconnectFromHost();

    int header = response.indexOf("\r\n\r\n");
    if (header != -1) {
        result = response.mid(header+4);
    }
    return true;
}
开发者ID:chenbaohai,项目名称:multiScreenClient,代码行数:34,代码来源:http.cpp


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