When multiple strings need to be sent in a message, special processing is required to extract each string. As mentioned above, the message header is 4 bytes in length, so we can use the message header to intercept the required length. Code: voidWidget: slot_udpReadyRead () {QByteArraybyteArray1; while (udpSocket-h
When multiple strings need to be sent in a message, special processing is required to extract each string. As mentioned above, the message header is 4 bytes in length, so we can use the message header to intercept the required length. Code: void Widget: slot_udpReadyRead () {QByteArray byteArray1; while (udpSocket-h
When multiple strings need to be sent in a message, special processing is required to extract each string. As mentioned above, the message header is 4 bytes in length, so we can use the message header to intercept the required length.
Check the Code:
Void Widget: callback () {QByteArray byteArray1; while (udpSocket-> hasPendingDatagrams () {callback (udpSocket-> pendingDatagramSize (); udpSocket-> readdat.pdf (byteArray1.data (), byteArray1.size ();} // extract the information in the server send back message QDataStream in1 (& byteArray1, QIODevice: ReadOnly); QTextCodec * codec = QTextCodec :: codecForName ("UTF-16BE"); // myStr1 quint32 Len1; in1> Len1; qDebug () <"Len1:" <
ToUnicode (byteArray1.right (byteArray1.length ()-4); qDebug () <"myStr1:" <
> Len2; qDebug () <"Len2:" <
ToUnicode (byteArray2.right (byteArray2.length ()-4); qDebug () <"mySt2:" <
< pre>
The running status is as follows:
<>