| CMakeLists.txt |
|
566 |
- |
| qpacket.cpp |
!
\class QPacket
\internal
\brief 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:
\code
int version = QDataStream::Qt_DefaultCompiledVersion;
QPacketProtocol protocol(...);
QPacket myPacket(version);
myPacket << "Hello world!" << 123;
protocol.send(myPacket.data());
\endcode
As long as both ends of the connection are using the QPacketProtocol class
and the same data stream version, the data within this packet will be
delivered unfragmented at the other end, ready for extraction.
\code
QByteArray greeting;
int count;
QPacket myPacket(version, protocol.read());
myPacket >> greeting >> count;
\endcode
Only packets constructed from raw byte arrays may be read from. Empty QPacket
instances are for transmission only and are considered "write only". Attempting
to read data from them will result in undefined behavior.
\ingroup io
\sa QPacketProtocol
|
2640 |
- |
| qpacket_p.h |
|
871 |
- |
| qpacketprotocol.cpp |
!
\class QPacketProtocol
\internal
\brief The QPacketProtocol class encapsulates communicating discrete packets
across fragmented IO channels, such as TCP sockets.
QPacketProtocol makes it simple to send arbitrary sized data "packets" across
fragmented transports such as TCP and UDP.
As transmission boundaries are not respected, sending packets over protocols
like TCP frequently involves "stitching" them back together at the receiver.
QPacketProtocol makes this easier by performing this task for you. Packet
data sent using QPacketProtocol is prepended with a 4-byte size header
allowing the receiving QPacketProtocol to buffer the packet internally until
it has all been received. QPacketProtocol does not perform any sanity
checking on the size or on the data, so this class should only be used in
prototyping or trusted situations where DOS attacks are unlikely.
QPacketProtocol does not perform any communications itself. Instead it can
operate on any QIODevice that supports the QIODevice::readyRead() signal. A
logical "packet" is simply a QByteArray. The following example how to send
data using QPacketProtocol.
\code
QTcpSocket socket;
// ... connect socket ...
QPacketProtocol protocol(&socket);
// Send a packet
QDataStream packet;
packet << "Hello world" << 123;
protocol.send(packet.data());
\endcode
Likewise, the following shows how to read data from QPacketProtocol, assuming
that the QPacketProtocol::readyRead() signal has been emitted.
\code
// ... QPacketProtocol::readyRead() is emitted ...
int a;
QByteArray b;
// Receive packet
QDataStream packet(protocol.read());
p >> a >> b;
\endcode
\ingroup io
|
8603 |
- |
| qpacketprotocol_p.h |
|
1072 |
- |
| qversionedpacket_p.h |
|
893 |
- |