send UdpPacket with WriteDatagram
Solved
General and Desktop
-
Hi
I want to send UDP packet from start point in QByteArrays datagram with specific length , How can i set start point(int type) in WriteDatagram line code?//sample code QUdpSocket::writeDatagram(const QByteArray &datagram, const QHostAddress &host, quint16 port)
-
You can't. There is writeDatagram for this.
Or you use QByteArray::mid -
How do you define your starting point?
one could be as folows when your starting point is after 10 bytes.
QUdpSocket *udp; ... udp->writeDatagram ( bytearray.mid ( 10 ), address, port );
also you can get a number of byte out of the byte array by
QByteArray shorterArray = ba.mid ( 10, 12 );
This would extract 12 bytes starting after the 10th byte of ba. With
udp->writeDatagram ( shorterArray, address, port );
or you can do
udp->writeDatagram ( ba.mid (10, 12), address, port );