Android QtNetwork
-
I have a software compiled for Windows and Android. Both are working ok. When i attached the QtNetwork to use QUdpSocket in windows is working ( it asks me for allow to port to open) and it is working fine. When i use it for android , android is not receiving data. What can i do ? This is my code
@ udpSocket->bind(QHostAddress("192.168.1.15"),5000);
udpSocket->joinMulticastGroup(QHostAddress("224.5.6.7"));
QHostAddress sender;
quint16 senderPort;
bytesReaded = this->udpSocket->readDatagram((char*)buffer,bufferLength,&sender, &senderPort);
@
this ip is the ip of android phone 192.168.1.15 -
did you set the Android permissions of your app correctly?
-
how can i set the permissions ?
-
You need to edit your manifest file.
read "this":http://doc-snapshot.qt-project.org/qtcreator-2.8/creator-deploying-android.html#editing-manifest-files and "this":http://developer.android.com/reference/android/Manifest.permission.html. -
I tested that and not work. I have the same problem on linux also... the network is not working. I am running Linux version on VMWare machine but i don't think that's a problem..
-
Hi,
I have my following code which guaranteed works on my phone but i'm not binding it to any particular address.
@
udpSocket = new QUdpSocket(this);
udpSocket->bind(15687, QUdpSocket::ShareAddress);
connect(udpSocket, SIGNAL(readyRead()),
this, SLOT(processPendingDatagrams()));void Sync::processPendingDatagrams()
{
QString stmp;
while (udpSocket->hasPendingDatagrams()) {
QByteArray datagram;
datagram.resize(udpSocket->pendingDatagramSize());
udpSocket->readDatagram(datagram.data(), datagram.size());
stmp = QString(datagram.data());
}
@You can try to add the joinMulticastGroup and see if above works.
Edit: I've also set android.permission.INTERNET permission
-
Everything i enter a get the message :
QAbstractSocket::ConnectedState!
I remember in windows it was working ok! -
Ok, now from OS point of view.
Is multicasting enabled on your machine ? use ifconfig command on your linux machine.
Eg. if interface is eth0
@ifconfig eth0@If it contains MULTICAST then it is enabled,
or Paste the output here -
Guys i found the solution but i don't know the reason qt is acting like that in linux
First Source code i use :
@
udpSocket->bind(QHostAddress("192.168.1.15"),5000);
udpSocket->joinMulticastGroup(QHostAddress("224.5.6.7"));
@Fix
@
udpSocket->bind(QHostAddress("192.168.1.15").AnyIPv4,5000);
udpSocket->joinMulticastGroup(QHostAddress("224.5.6.7"));
@
As you can see i have added AnyIPv4.
Why that's happened ?
When do we use AnyIPv4?