pelican/examples/example-2/emulator/StreamEmulator.cpp
/**
 * Method to create the TCP device which is used to send emulated data.
 *
 * To connect the TCP socket requires that a TCP server has been created.
 * In this example the server is created in the StreamChunker in the server.
 *
 * This function therefore blocks, with a timeout of 10 seconds, repeatedly
 * trying to connect to the server every 0.1 seconds.
 *
 * If, after 10 seconds, a connection can't be established an exception is
 * thrown causing the emulator binary to terminate.
 */
Method to create the TCP device which is used to send emulated data.
To connect the TCP socket requires that a TCP server has been created.
In this example the server is created in the StreamChunker in the server.

This function therefore blocks, with a timeout of 10 seconds, repeatedly
trying to connect to the server every 0.1 seconds.

If, after 10 seconds, a connection can't be established an exception is
thrown causing the emulator binary to terminate.
Method to create the TCP device which is used to send emulated data . To connect the TCP socket requires that a TCP server has been created . In this example the server is created in the StreamChunker in the server . This function therefore blocks with a timeout of 10 seconds repeatedly trying to connect to the server every 0 . 1 seconds . If after 10 seconds a connection can ' t be established an exception is thrown causing the emulator binary to terminate .
QIODevice* StreamEmulator::createDevice()
{
    cout << endl;
    QTcpSocket* socket = new QTcpSocket();
    socket->abort();
    socket->connectToHost(host_, port_);
    int maxTries = 100;
    int tryCount =  0;
    int delay = 1e5;  
    cout << "Attempting to connect to server [timeout = "
         << delay/1e6 * maxTries << "s]\n..." << flush;
    while (!socket->waitForConnected(-1) && tryCount <= maxTries) {
        socket->connectToHost(host_, port_);
        usleep(delay);
        if (tryCount%5 == 0)
            cout << "." << flush;
        tryCount++;
    }
    if (!socket->waitForConnected(-1)) {
        throw QString("\nERROR: StreamEmulator::createDevice(): Timed out.  ") +
            QString(socket->errorString()) + QString(".");
    }
    else {
        cout << " Connected!" <<endl << endl;
    }
    return socket;
}
QIODevice * StreamEmulator :: createDevice ( ) { cout << endl ; QTcpSocket * socket = new QTcpSocket ( ) ; socket -> abort ( ) ; socket -> connectToHost ( host_ , port_ ) ; int maxTries = 100 ; int tryCount = 0 ; int delay = 1e5 ; cout << " " << delay / 1e6 * maxTries << " \n " << flush ; while ( ! socket -> waitForConnected ( -1 ) && tryCount <= maxTries ) { socket -> connectToHost ( host_ , port_ ) ; usleep ( delay ) ; if ( tryCount % 5 == 0 ) cout << " " << flush ; tryCount ++ ; } if ( ! socket -> waitForConnected ( -1 ) ) { throw QString ( " \n " ) + QString ( socket -> errorString ( ) ) + QString ( " " ) ; } else { cout << " " << endl << endl ; } return socket ; }
Method to create the TCP device which is used to send emulated data.
Method to create the TCP device which is used to send emulated data .
// Block until the device can be connected... // TODO make timeout XML configurable. // 0.1 seconds