Вот код udpSocket = new QUdpSocket(this); groupAddress = QHostAddress("239.255.43.21"); if(!udpSocket->bind(QHostAddress(QHostAddress::AnyIPv4), portMulti, QUdpSocket::ReuseAddressHint|QUdpSocket::ShareAddress)) { qDebug() <<"Бида все пропало1"; } if(!udpSocket->joinMulticastGroup(groupAddress)) { qDebug() <<"Бида все пропало2"; } connect(udpSocket, SIGNAL(readyRead()),this,SLOT(processPendingDatagrams())); 

On linux, this code works without problems, but on windows it works only if I enter both the server’s internal ip server’s address into the server and the client (192.158.0.102 well, or there that you understand that), if I enter other ipes, nothing works, say what I’m doing so how to fix it please. Really needed.
I throw the code from the android client, someone may want to know what is netak, I have no idea why it works only Linuxe.

 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 a solution is needed. The trouble is that I installed genymotion, genymotion installed virtualbox, virtualbox installed more network adapters interfaces, well, the Network and Sharing Center-> Adapter parameter changes, + 2 adapters were added there. When I tested without these adapters, or on linux, the server is apparently connected. to 1 network interface correct, as it is. But when there were a lot of them, an error occurred. But how now, fix it all, tried to connect interfaces yet does not help, and what to connect? It is necessary correct, the solution the code is shorter, with a detour of this problem. In advance, the greatest ATP if anyone can help.

  • Well, probably on Windows, the firewall blocks the connection. - vadrozh
  • Firewall disabled. - Madoka Magica
  • If you have an internal IP, then there are routing tools? - vadrozh
  • Well, I meant Wifi router. Those. I have a smartphone on android on android and a computer in 1 wifi network. 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. need to. ATP for the answer 3 day I sit I do not understand. Another idea first when checking the firewall was on, I immediately turned it off. when it didn't work, but the result was 0 ( - Madoka Magica
  • Another feeling is that here it is udpSocket-> joinMulticastGroup (groupAddress); before the bulb, yes it returns true, but for example when I delete it or don't delete it all the same if I put InetAddress groupAddr = InetAddress.getByName ("192.168.0.102") in the android client, but if InetAddress groupAddr = InetAddress.getByName ("239.255 .43.21 ") does not work anyway, but the packages on the computer come in. I installed whirelshark checked. - Madoka Magica

1 answer 1

 Вот код udpSocket = new QUdpSocket(this); groupAddress = QHostAddress("255.255.255.255"); if(!udpSocket->bind(QHostAddress(QHostAddress::AnyIPv4), portMulti, QUdpSocket::ReuseAddressHint|QUdpSocket::ShareAddress)) { qDebug() <<"Бида все пропало1"; } if(!udpSocket->joinMulticastGroup(groupAddress)) { qDebug() <<"Бида все пропало2"; } udpSocket->setMulticastInterface( getNetworkInterfaceByAddress("192.168.0.102") ); connect(udpSocket, SIGNAL(readyRead()),this,SLOT(processPendingDatagrams())); QNetworkInterface getNetworkInterfaceByAddress(QString adr) { QList<QNetworkInterface> il(QNetworkInterface::allInterfaces()); for (int i = 0; i < il.size(); i++) { QList<QNetworkAddressEntry> ade(il[i].addressEntries()); for (int j = 0; j < ade.size(); j++) { if (ade[j].ip().toString() == adr) return il[i]; } } return QNetworkInterface(); } 

Here is a solution, but alas, for some reason, it works for me only with 255.255.255.255, although I naturally didn’t go through all the ip, if anyone knows why write something while I’m writing so. In short, you need to add the correct interface and the correct invented ip campaign. By the way, the getNetworkInterfaceByAddress (QString adr) is like working, but the point is what I wrote above.