QUdpSocket cannot receive datagram
-
Hi, I'm trying to receive datagrams from a Raspberry. where I use Linux native sockets to send them. It is not the first time I use QUdpSocket and I'm quite familiar with Qt sockets functionalities thus it is very strange that I'm dealing with this problem.
Briefly although Wireshark is able to sniff all the packets I expect to receive, it seems that no one of them is received by QUdpSocket since it doesn't emit any readyRead() signal. I also tried to inhibit the firewall... nothing to do. I really don't understand if the problem is in my code or if in a detail that currently I can't catch. However this is my code:Listener::Listener(QWidget *parent) : QMainWindow(parent) { std::cout<<"ip addresses list:"<<std::endl; int i = 0; for(QHostAddress addr: QNetworkInterface::allAddresses()) std::cout<<"address "<<++i<<": "<<addr.toString().toStdString()<<std::endl; skt = new QUdpSocket(this); std::cout<<std::endl<<"Please select address to bind: "<<std::endl; scanf("%d",&i); auto addr = QNetworkInterface::allAddresses()[i-1]; std::cout<<"binding to address: "<<addr.toString().toStdString()<<std::endl; if(!skt->bind(QHostAddress(addr),5555)) std::cout<<"can't bind!"<<std::endl; connect(skt,&QUdpSocket::readyRead,this,&Listener::readPacket); log = new QTextEdit(this); this->setCentralWidget(log); } void Listener::readPacket(){ char data[100]; std::cout<<"arrived"<<std::endl; log->append("arrived"); skt->readAll(); }please don't focus on the usefullness of readPacket(), it only needs to let me understand if readyRead signal is emitted.
Can anyone help me? -
Guys, thank you very much for help, I just realised that I built exception for windows defender firewall but not for avast one. It definitely was the firewall, thank you for your time anyway. Regards.
-
first thing you should do is simplify by binding to the default 0.0.0.0 address instead of a specific interface...then look at lsof -i to confirm the listener is active.
After than send some UDP to it via socat or nc
-
first thing you should do is simplify by binding to the default 0.0.0.0 address instead of a specific interface...then look at lsof -i to confirm the listener is active.
After than send some UDP to it via socat or nc
@Kent-Dorfman said in QUdpSocket cannot receive datagram:
lsof
Yes of course i tried also with more general bindings but it is exactly the same. Then I also listened to your advice by using socat for testing at least the reception but, again, nothing to do. I forgot to say that i'm developing the Listener on Windows 10, so I should find another way to make sure that the socket is active.
-
@Emanuele96 Hope the application binds to specified address successfully,
if so try to send some sample data from the same application so as to verify whether it receives the data to the required port(5555) from the same machine,Do you verify the wireshark data is addressed to the the required address and port number (5555)?
-
@Emanuele96 Hope the application binds to specified address successfully,
if so try to send some sample data from the same application so as to verify whether it receives the data to the required port(5555) from the same machine,Do you verify the wireshark data is addressed to the the required address and port number (5555)?
@nagesh they are all trials i performed yet. I'm sure that it is correctly binded because if i send a message wireshark catch a packet as address source the correct one and port source 5555, as specified in the code
-
@nagesh said in QUdpSocket cannot receive datagram:
if so try to send some sample data from the same application so as to verify whether it receives the data to the required port(5555) from the same machine,
Have you checked this?..in the same application send the data to required port & receive the data
-
@nagesh said in QUdpSocket cannot receive datagram:
if so try to send some sample data from the same application so as to verify whether it receives the data to the required port(5555) from the same machine,
Have you checked this?..in the same application send the data to required port & receive the data
@nagesh yes, I tried and nothing arrives to the listener. According to me it is not a problem of senders cause, once again, Wireshark can hear all the packets i send to my listener...
-
Guys, thank you very much for help, I just realised that I built exception for windows defender firewall but not for avast one. It definitely was the firewall, thank you for your time anyway. Regards.