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
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
To copy to clipboard, switch view to plain text mode
I modified broadcastreceiver as follow:
//! [0]
//! [0]
//! [0]
udpSocket = new QUdpSocket(this);
udpSocket->bind(45454, QUdpSocket::ShareAddress);
udpSocket->connectToHost(QHostAddress(QHostAddress::Any),0); // <- added line
//! [0]
To copy to clipboard, switch view to plain text mode
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
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
udp6 0 0 ::1:45454 ::1:* ESTABLISHED 11488/broadcastrece
To copy to clipboard, switch view to plain text mode
I wonder why it seems different local address, and where am I wrong.
here is attached the examples
qt5-examples.tar.gz
best regards
Max
Bookmarks