void TCPConnectionManagerTest::test_send()
{
    // Use Case:
    // client requests a connection
    // expect client to be registered for any data
    StreamDataRequest req;
    DataSpec require;
    require.addStreamData("testData");
    req.addDataOption(require);

    QTcpSocket* client = _createClient();
    _sendRequest( client, req );
    QCoreApplication::processEvents();
    CPPUNIT_ASSERT_EQUAL( 1, _server->clientsForStream("testData") );
    TestDataBlob blob;
    blob.setData("sometestData");
    _server->send("testData",&blob);
    sleep(1);

    CPPUNIT_ASSERT( client->state() == QAbstractSocket::ConnectedState );
    boost::shared_ptr<ServerResponse> r = _clientProtocol->receive(*client);
    CPPUNIT_ASSERT( r->type() == ServerResponse::Blob );
    DataBlobResponse* res = static_cast<DataBlobResponse*>(r.get());
    CPPUNIT_ASSERT( res->dataName() == "testData" );
    CPPUNIT_ASSERT( res->blobClass() == "TestDataBlob" );
    TestDataBlob recvBlob;
    recvBlob.deserialise(*client, res->byteOrder());
    CPPUNIT_ASSERT(recvBlob == blob);

}
// Read data from the Pelican Lofar pipeline
void PelicanBlobClient::getData(QHash<QString, DataBlob*>& dataHash)
{
    // Check that we are still connected to server, if not reconnect
    if (_tcpSocket->state() == QAbstractSocket::UnconnectedState) {
        cout << "PelicanBlobClient: Disconnected from server, reconnecting." << endl;
        connectToLofarPelican();
    }

    // Get a pointer to the data blob from the hash.
    SpectrumDataSetStokes* blob = (SpectrumDataSetStokes*) dataHash["SpectrumDataSetStokes"];

    // Wait for data to be available to socket, and read
    _tcpSocket->waitForReadyRead();
    boost::shared_ptr<ServerResponse> response = _protocol->receive(*_tcpSocket);

    // Check what type of response we have
    switch(response->type())
    {
        case ServerResponse::Error:  // Error occurred!!
        {
            cerr << "PelicanBlobClient: Server Error: '"
                 << response->message().toStdString() << "'" << endl;
            break;
        }
        case ServerResponse::Blob: // We have received a blob
        {
            DataBlobResponse* res = (DataBlobResponse*)response.get();
            while (_tcpSocket->bytesAvailable() < (qint64)res->dataSize())
                _tcpSocket -> waitForReadyRead(-1);
            blob->deserialise(*_tcpSocket, res->byteOrder());
            break;
        }
        case ServerResponse::StreamData: // We have stream data
        {
            cout << "Stream Data" << endl;
            break;
        }
        case ServerResponse::ServiceData:  // We have service data
        {
            cout << "Service Data" << endl;
            break;
        }
        default:
            cerr << "PelicanBlobClient: Unknown Response" << endl;
            break;
    }
}