Logo Search packages:      
Sourcecode: qt4-x11 version File versions

void Server::sendFortune (  )  [private, slot]

[4]

[5]

[4] //! [6]

[6] //! [7]

[7] //! [8]

[5]

Definition at line 96 of file server.cpp.

References QList< T >::at(), QObject::connect(), QObject::deleteLater(), QDataStream::device(), QLocalSocket::disconnectFromServer(), QLocalSocket::flush(), QLocalServer::nextPendingConnection(), QIODevice::seek(), QDataStream::setVersion(), QByteArray::size(), QList< T >::size(), and QIODevice::write().

Referenced by Server().

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

    QLocalSocket *clientConnection = server->nextPendingConnection();
    connect(clientConnection, SIGNAL(disconnected()),
            clientConnection, SLOT(deleteLater()));

    clientConnection->write(block);
    clientConnection->flush();
    clientConnection->disconnectFromServer();
}


Generated by  Doxygen 1.6.0   Back to index