Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QUdpSocket bytesWritten() signal separates datagrams
Qt 6.11 is out! See what's new in the release blog

QUdpSocket bytesWritten() signal separates datagrams

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    iamnp
    wrote on last edited by
    #1

    I have a question about bytesWritten() signal of Qt's QUdpSocket class. Docs (http://qt-project.org/doc/qt-5.0/qtnetwork/qudpsocket.html) says:

    The socket emits the bytesWritten() signal every time a datagram is written to the network.

    and

    An incoming datagram should be read when you receive the readyRead() signal, otherwise this signal will not be > emitted for the next datagram.

    Does it mean that if I send 10 bytes I will get readyRead() called only once and have 10 bytes available? And what is the point of bytesWritten() if we have readyRead()? What should I use?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      bytesWritten is for when you write something (sender socket), readyRead is for when you receive something (receiver socket)

      If you only send one datagram then yes, you will only receive one

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • IamSumitI Offline
        IamSumitI Offline
        IamSumit
        wrote on last edited by
        #3

        Hello lamnp,

        I think You are in confusion..
        readyRead() emits when there is something to read.
        byteswritten() emits when there is something to write.

        You can use socket->Write() function as well inside readyRead()

        But in QUdpSocket we have two functions :
        1)For Writing the datagram --->
        Syntax :
        qint64 QUdpSocket::writeDatagram ( const char * data, qint64 size, const QHostAddress & address, quint16 port )
        e.g ;
        Socket->writeDatagram(data,QHostAddress::LocalHost,1234);
        2)For Reading the datagram--->
        Syntax :
        qint64 QUdpSocket::readDatagram ( char * data, qint64 maxSize, QHostAddress * address = 0, quint16 * port = 0 )
        e.g;
        Socket->readDatagram(Buffer.data(),Buffer.size(),&ipaddress,&portno);

        I hope it will help you..

        Be Cute

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved