[SOLVED] Udp Broadcast Receive problem



  • I need to send a broadcast packet and receive the reply from some devices on the network.
    The sender works correctly, but the receiver works only on the packet sent from netcat. This is my source:

    @Discovery::Discovery(QObject *parent) :
    QObject(parent)
    {

    udpSocket = new QUdpSocket(this);
    
    if(udpSocket->bind(udpSocket->localPort()))
        qDebug() << "Bind on port" << udpSocket->localPort();
    else
        qDebug() << "Bind failed";
    
    connect(udpSocket,SIGNAL(readyRead()),this,SLOT(rxBroadcast()));
    

    }

    void Discovery::startBroadcasting()
    {
    qDebug() << "Start broadcast";

     QByteArray datagram;
     datagram.append(messageDiscovery);
    
     udpSocket->writeDatagram(datagram.data(), datagram.size(), QHostAddress::Broadcast, portDiscovery);
    

    }

    void Discovery::rxBroadcast()
    {

    QByteArray buffer;
    buffer.resize(udpSocket->pendingDatagramSize());
    
    QHostAddress sender;
    quint16 senderPort;
    
    udpSocket->readDatagram(buffer.data(), buffer.size(),
                         &sender, &senderPort);
    
    qDebug() << "Message from: " << sender.toString();
    qDebug() << "Message port: " << senderPort;
    qDebug() << "Message: " << buffer;
    
    qDebug() << " RX ";
    

    }
    @

    where "portDiscovery" is 65535 and "messageDiscovery" is a string of three char.

    The packet is send correctly and I can see from wireshark the correct reply from 4 devices.
    From wireshark:

    1 PACKET: 10.10.20.76 -> 255.255.255.255 UDP (source port: 42147 - destination port: 65535)
    2 PACKET: 10.10.30.114 -> 10.10.20.76 UDP (source port: 65535 - destination port: 42147)
    3 PACKET: 10.10.30.119 -> 10.10.20.76 UDP (source port: 65535 - destination port: 42147)
    4 PACKET: 10.10.30.115 -> 10.10.20.76 UDP (source port: 65535 - destination port: 42147)
    5 PACKET: 10.10.30.116 -> 10.10.20.76 UDP (source port: 65535 - destination port: 42147)
    ...

    In this case the my app is on 10.10.20.76 and with this code I don't receive anything.

    If I try send a packet with netcat:
    @echo -n "hello" | nc -4u localhost 42147@

    I obtain this output correctly:
    @Message from: "127.0.0.1"
    Message port: 55424
    Message: "hello"
    RX @

    how It's possible?

    Thank's



  • The problem was in the firewall in my linux machine
    Sorry


Log in to reply
 

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