E
E
elfenlied2017-02-11 16:35:36
Qt
elfenlied, 2017-02-11 16:35:36

QUdpSocket does not accept packets on windows but works on linux why?

groupAddress = QHostAddress(/*"192.168.0.102"*/"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, 45455, QUdpSocket::ShareAddress);
    udpSocket->joinMulticastGroup(groupAddress);

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

Actually the code from a simple example doc.qt.io/qt-5/qtnetwork-multicastr...er-example.html Everything works on linux, but on windows 10 (I haven't checked others yet) it doesn't want to accept packets. More precisely, if I connect to 192.168.0.102, well, the internal ip of the computer works, but I need the left ip (for example, 239.255.43.21 as in the example) so that each android device from the wifi network can connect to the server without knowing the server ip. I don’t understand what’s wrong, everything works on Linux. In short, please don’t pass by if you know something.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
elfenlied, 2017-02-11
@elfenlied

Firewall turned off. "multicast exceptions" try catch ? I tried checking like this

if(!udpSocket->bind(QHostAddress(QHostAddress::AnyIPv4), portMulti,  QUdpSocket::ReuseAddressHint|QUdpSocket::ShareAddress)) {
   qDebug() <<"Бида все пропало1";
}
if(!udpSocket->joinMulticastGroup(groupAddress)) {
   qDebug() <<"Бида все пропало2";
}

More shortly errors like does not jump out. In general, everything responds only to the internal ip of the computer from my wi-fi network (192.168.0.102). firewall off Maybe something else off. necessary. ATP for the answer 2 days I sit I do not understand. Another idea at first when I checked the firewall was on, I immediately turned it off. when it didn’t work, but the result is 0 (
I’m throwing the code from the android client, maybe someone will figure out what’s wrong, I have no idea why it only works on Linux.
socket = new DatagramSocket(/*45454*/);
      socket.setBroadcast(true);
     InetAddress groupAddr = InetAddress.getByName("239.255.43.21"); //на этом (выдуманный) работает только на linux
     //InetAddress groupAddr = InetAddress.getByName("192.168.0.102"); //на этом адресе работает
      byte[] outbuf = makeStartPacket();
      sendPacket(socket, groupAddr, outbuf);

 private byte[] makeStartPacket() {
    byte[] outPack =  ("Ляляля").getBytes();
    return outPack;
  }
private void sendPacket(DatagramSocket socket, InetAddress groupAddr, byte[] outbuf)
      throws IOException {
    DatagramPacket packet;
    packet = new DatagramPacket(outbuf, outbuf.length, groupAddr,
        /*9901*//*2425*//*multiPort*/45455);
    //outbuf = createLegacyDiscoveryRequest(socket);
    socket.send(packet);

  }

The problem is found, but the decision is very necessary. The trouble is that I installed genymotion, genymotion installed virtualbox, virtualbox also installed network adapters interfaces well, in short, Network and Sharing Center-> Changes in the adapter parameter, + 2 adapters were added there. When I tested without these adapters, or on linux, the server seems to be connected. to 1 network interface correct, something like this. But when there were a lot of them, a mistake happened. But how now, to fix it all, I tried connecting interfaces until it helps, and which one to connect? You need the correct one, in short, you need a solution code, with a bypass of this problem. Thanks in advance if anyone can help.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question