Communication between the Qt client and the Erlang server (2): obtain multiple strings

Source: Internet
Author: User
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:

<>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.