Results 1 to 6 of 6

Thread: Reading last datagram in UDP network

  1. #1
    Join Date
    Feb 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Reading last datagram in UDP network

    Hello,

    I have a server which send datagram in very high rate. however I want to sample
    the data every one second and i want to get the last datagram. I don't want to get any signals of readyread between my requests to sample the data and i want fast access to the last datagram. any solution?

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

    Default Re: Reading last datagram in UDP network

    any solution?
    to what problem?
    or should we guess?
    ==========================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. #3
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reading last datagram in UDP network

    Here's a concept:
    Qt Code:
    1. QByteArray dgram;
    2. while (socket->hasPendingDatagrams()) {
    3. // do some resize magic
    4. socket->readDatagram(dgram.data()...);
    5. }
    6. // dgram == last datagram, or null.
    7. if (!dgram.isNull())
    8. parseDatagram(dgram);
    To copy to clipboard, switch view to plain text mode 
    There's a lot you can think of to fill in the details by just reading the documentation.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  4. #4
    Join Date
    Feb 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Reading last datagram in UDP network

    I have a server which send realtime data in very fast rate (every 1 milisecond) but I need to read the data in low rate (every 1 second). The data is sent as datagram in UDP network. I need to read only the last datagram because all the previous datagrams are obsolete for me. if I read every datagram that I get I will also work in 1 milisecond. If I wait 1 second and then connect to readyRead signal i will have to iterate all the datagram untill I reach the last one (and then I will have to disconnect readyRead). I want to be able to read the last datagram every one second in simple way.

  5. #5
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reading last datagram in UDP network

    This is probably as simple as you can get it. The QUdpSocket doesn't give you the option of discarding things in another way than reading the messages and discarding them yourself.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

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

    Default Re: Reading last datagram in UDP network

    One thing to note - there is no concept of "last" datagram with UDP. UDP doesn't guarantee that the sending order of datagrams is preserved on the receiving end so it may happen that the last datagram you receive is the first one of the whole series that was sent. Or that you don't receive the datagram at all. A common misconception in network programming is to treat the sender and receiver as one linked system (ignoring the nature of protocols connecting the systems) instead of treating them as autonomous systems exchanging data according to a set of rules (the protocol).
    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. reading network configuration
    By Tomasz in forum Newbie
    Replies: 1
    Last Post: 9th August 2010, 19:10
  2. Reading TCP datagram header by Qt
    By Kill3rReaper in forum Qt Programming
    Replies: 11
    Last Post: 8th June 2010, 12:49
  3. QUdpSocket - how to get destination address of a datagram?
    By nelliekins in forum Qt Programming
    Replies: 0
    Last Post: 17th September 2009, 08:59
  4. UDP datagram receive
    By mdannenb in forum Qt Programming
    Replies: 8
    Last Post: 27th July 2008, 03:30
  5. help in QT network!
    By bbc58206 in forum Qt Programming
    Replies: 3
    Last Post: 10th September 2007, 05:00

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.