Page 2 of 2 FirstFirst 12
Results 21 to 25 of 25

Thread: Formatting a packet with different types then send it over TCP

  1. #21
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Formatting a packet with different types then send it over TCP

    So what happens in the second while loop if all your bytes arrived at once and were available when you entered the routine? What about if only some of the message bytes have been received? What if some of the bytes are delayed?

    Have you set a breakpoint and single-stepped this?
    Last edited by ChrisW67; 10th June 2011 at 02:48.

  2. #22
    Join Date
    Feb 2011
    Posts
    64
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Formatting a packet with different types then send it over TCP

    The first loop to read 6 bytes(2 bytes + 4 bytes of size), in the second loop I block until I read the whole packet, so this all I get. If you have better solution please post it.

  3. #23
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Formatting a packet with different types then send it over TCP

    Quote Originally Posted by SIFE View Post
    in the second loop I block until I read the whole packet
    What if two packets arrive at once?

    If you have better solution please post it.
    My universal approach is to use signals and slots, buffer incoming data and process the buffer in a while loop as long as there is enough data in it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #24
    Join Date
    Feb 2011
    Posts
    64
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Formatting a packet with different types then send it over TCP

    My universal approach is to use signals and slots, buffer incoming data and process the buffer in a while loop as long as there is enough data in it.
    Would you say it in code .

  5. #25
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Formatting a packet with different types then send it over TCP

    If you want code then search the forum. I can give you a short explanation -- connect to the socket's readyRead() signal, append all pending data to your own buffer and process the buffer in a while loop according to the following pseudo-code logic:
    Qt Code:
    1. buffer += socket.readAll();
    2. while(buffer.size >= expectedBlockSize) {
    3. data = buffer.take(expectedBlockSize);
    4. process(data);
    5. }
    To copy to clipboard, switch view to plain text mode 
    Of course expectedBlockSize will depend on what you expect to receive.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. MAC address of UDP packet's sender
    By mastupristi in forum Qt Programming
    Replies: 3
    Last Post: 31st January 2011, 13:12
  2. Replies: 4
    Last Post: 10th December 2009, 16:37
  3. Packet getting fragmented when sending over QTcpSocket
    By arturo182 in forum Qt Programming
    Replies: 14
    Last Post: 5th August 2009, 23:11
  4. how to send ICMP packet
    By eleanor in forum Qt Programming
    Replies: 2
    Last Post: 30th October 2007, 14:23
  5. QtNetwork send ICMP Packet
    By SlowTree in forum Qt Programming
    Replies: 3
    Last Post: 29th October 2007, 20:13

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.