QAbstractSocket::connectToHost(), receive broadcast UDPdatagrams?



  • 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:

    //! [0]
        udpSocket = new QUdpSocket(this);
        udpSocket->bind(45454, QUdpSocket::ShareAddress);
        udpSocket->connectToHost(QHostAddress(QHostAddress::Any),0); // <- added line
    //! [0]
    

    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.

    best regards
    Max


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.