QUdpSocket bytesWritten() signal separates datagrams
-
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?
-
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
-
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..