Home · All Namespaces · All Classes · Grouped Classes · Modules · Functions |
The QPacket class encapsulates an unfragmentable packet of data to be transmitted by QPacketProtocol. More...
#include <QPacket>
Inherits QDataStream.
The QPacket class encapsulates an unfragmentable packet of data to be transmitted by QPacketProtocol.
The QPacket class works together with QPacketProtocol to make it simple to send arbitrary sized data "packets" across fragmented transports such as TCP and UDP.
QPacket provides a QDataStream interface to an unfragmentable packet. Applications should construct a QPacket, propagate it with data and then transmit it over a QPacketProtocol instance. For example:
QPacketProtocol protocol(...); QPacket myPacket; myPacket << "Hello world!" << 123; protocol.send(myPacket);
As long as both ends of the connection are using the QPacketProtocol class, the data within this packet will be delivered unfragmented at the other end, ready for extraction.
QByteArray greeting; int count; QPacket myPacket = protocol.read(); myPacket >> greeting >> count;
Only packets returned from QPacketProtocol::read() may be read from. QPacket instances constructed by directly by applications are for transmission only and are considered "write only". Attempting to read data from them will result in undefined behaviour.
See also QPacketProtocol.
Constructs an empty write-only packet.
Creates a copy of other. The initial stream positions are shared, but the two packets are otherwise independant.
Destroys the QPacket instance.
Clears data in the packet. This is useful for reusing one writable packet. For example
QPacketProtocol protocol(...); QPacket packet; packet << "Hello world!" << 123; protocol.send(packet); packet.clear(); packet << "Goodbyte world!" << 789; protocol.send(packet);
Returns true if this packet is empty - that is, contains no data.
Copyright © 2009 Trolltech | Trademarks | Qt Extended 4.4.3 |