Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Udp Broadcast Receive problem
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Udp Broadcast Receive problem

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 5.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tycos
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • T Offline
      T Offline
      Tycos
      wrote on last edited by
      #2

      The problem was in the firewall in my linux machine
      Sorry

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved