Nominate our 2022 Qt Champions!

Qt5 discard udp datagram without reading.

  • Hello,

    If a server receive two much data, its strategy is to discard the packets.

    Is it possible to discard a UDP datagram and still get notified for the next ones?
    The goal is to minimze the memory needed by an application to face offending packets.

    I would like to avoid to have to read them (because I will discard them anyway). But this should only concern one -offending- udp datagram.

    Alternatively, is reading 1 byte sufficient?


  • Lifetime Qt Champion


    From QUdpSocket::readDatagram's documentation setting maxSize to 0 will discard the datagram.

    Hope it helps

  • ooops.. Missed that line.

    Thank you

Log in to reply