2

I have a problem for connection 2 computers. First (transmitter) run's on windows and second run's on linux (ubuntu 16.04). I'm transfer data through QUdpSocket between this 2 machines by local , but when transmit pass through, receiver catch nothing (I mean QT shows nothing). For check, is it work correct, i've used wireshark and it shows that it is connection between machines, all packets pass through. But QT show nothing! I've used simple qt example about receiving multicast packets. What am I do wrong?

enter image description here

On 2 windows machines all works correct.

my ip is 192.168.1.1 and netmask 255.255.255.0

I've add this code , see it below. I also add wireshark printscreen.

#include <QtWidgets>
#include <QtNetwork>
#include "receiver.h"

Receiver::Receiver(QWidget *parent)
    : QDialog(parent)
{
    groupAddress = QHostAddress("226.1.1.1");//QHostAddress("239.255.43.21");

    statusLabel = new QLabel(tr("Listening for multicasted messages"));
    quitButton = new QPushButton(tr("&Quit"));

    udpSocket = new QUdpSocket(this);
    udpSocket->bind(QHostAddress::AnyIPv4, 50100,QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint );//udpSocket->bind(QHostAddress::AnyIPv4, 45454, );
    //udpSocket->setSocketOption(QAbstractSocket::MulticastTtlOption,QVariant(1));
    //udpSocket->setMulticastInterface(QNetworkInterface::interfaceFromName(groupAddress.toString())); //getInterfaceByAddress()
    udpSocket->joinMulticastGroup(groupAddress);


    //bool flag = groupAddress.isMulticast();

    connect(udpSocket, SIGNAL(readyRead()),
            this, SLOT(processPendingDatagrams()));
    connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));

    QHBoxLayout *buttonLayout = new QHBoxLayout;
    buttonLayout->addStretch(1);
    buttonLayout->addWidget(quitButton);
    buttonLayout->addStretch(1);

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(statusLabel);
    mainLayout->addLayout(buttonLayout);
    setLayout(mainLayout);

    setWindowTitle(tr("Multicast Receiver"));
}

void Receiver::processPendingDatagrams()
{
    while (udpSocket->hasPendingDatagrams()) {
        QByteArray datagram;
        datagram.resize(udpSocket->pendingDatagramSize());
        udpSocket->readDatagram(datagram.data(), datagram.size());
        statusLabel->setText(tr("Received datagram: \"%1\"").arg(datagram.data()));
    }
}
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Albert
  • 81
  • 2
  • 8
  • Does `udpSocket->joinMulticastGroup(groupAddress);` return true? – Deedee Megadoodoo Oct 17 '17 at 15:00
  • I would check the results of the calls that can return true/false, particularly `bind()` and `joinMulticastGroup()`. Also, you have `setMulticastInterface()` commented out, if you have more than one network interface, it may not be binding to the one you expect. – docsteer Oct 17 '17 at 15:28
  • Yes, it return true. – Albert Oct 18 '17 at 08:42
  • joinMulticastGroup() showed true. You shouldn't watch commented lines. It was just one of trying to do work for binding. – Albert Oct 18 '17 at 09:42

0 Answers0