Results 1 to 5 of 5

Thread: Splitting data so it fits into datagrams

  1. #1
    Join Date
    Feb 2007
    Posts
    13
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Splitting data so it fits into datagrams

    Hi

    I want to send pics over a network using udpsocket. The problem is that I don't know how to split my data so that it fits into the maximum datagram size that this class admits. Any suggestions?

    (What I have now is an IplImage (the image format from the OpenCV libraries). In the future it will be probably substituted by a encoded picture in H263, but I guess the problem is the same.

    Thanks...

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Splitting data so it fits into datagrams

    You mean something along the lines of:
    Qt Code:
    1. for(int i=0;i<imageSize; i++)
    2. {
    3. if(imageSize-i > datagramSize)
    4. memcopy(p_datagram,p_image+i,datagramSize);
    5. else memcopy(p_datagram,p_image+i,imageSize-i);
    6. //send datagram
    7. }
    To copy to clipboard, switch view to plain text mode 
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. The following user says thank you to high_flyer for this useful post:

    toratora (9th May 2007)

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

    Default Re: Splitting data so it fits into datagrams

    There is one problem here - datagrams can be received in different order (or even lost completely) than they were sent, so it could be useful to include information about which octets of the file are transmitted in the datagram. Then you'll be able to assemble the image back on the target host properly. Also provide some kind of feedback in a form of positive or negative acknowledgements from the target host.

  5. The following user says thank you to wysota for this useful post:

    toratora (9th May 2007)

  6. #4
    Join Date
    Feb 2007
    Posts
    13
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Splitting data so it fits into datagrams

    Thanks for the reply

    Ya, that's the problem, the order is key.

    That's why I was asking, in case there's something on Qt that can do that or any peace of code on the Internet anyone might know.

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

    Default Re: Splitting data so it fits into datagrams

    Simply invent and apply some kind of "header" to each datagram.

Similar Threads

  1. QSqlQueryModel data update
    By psi in forum Qt Programming
    Replies: 4
    Last Post: 20th July 2012, 03:59
  2. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53
  3. How to convert binary data to hexadecimal data
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 8th March 2006, 16:17
  4. Replies: 16
    Last Post: 7th March 2006, 15:57

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.