Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QAbstractSocket::connectToHost(), receive broadcast UDPdatagrams?
mastupristi last edited by A Former User
Can I use QAbstractSocket::connectToHost() to receive broadcast udp datagrams?
If I try the unmodified broadcastsender/receiver all works and netstat is:
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name udp6 0 0 :::52337 :::* 12185/./broadcastse udp6 0 0 :::45454 :::* 12172/broadcastrece
I modified broadcastreceiver as follow:
//!  udpSocket = new QUdpSocket(this); udpSocket->bind(45454, QUdpSocket::ShareAddress); udpSocket->connectToHost(QHostAddress(QHostAddress::Any),0); // <- added line //! 
Now it does not receive broadcast datagrams, but it receive correctly unicast datagrams.
the netstat command report is:
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name udp6 0 0 ::1:45454 ::1:* ESTABLISHED 11488/broadcastrece
I wonder why it seems different local address, and where am I wrong.