Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 6

Qt-interest Archive, August 2006
QUdpSocket doesn't receive data


Message 1 in thread

Hello,

I have a small Qt4 program which listens on Port 5551 Udp and should
print out received data to the console.
I'm sending Udp data from a PPC and a Java program and wireshark can
receive this data.
When I'm debugging my Qt-app I see that my app is never reaching the
SLOT where to process the Udp data, so I think the SIGNAL readyRead() is
never send out.
Where is the problem, that I cannot recieve Udp data???

Regards,

Patrick

-------------------------------------------------------------------------

main.cpp:
=========
#include <QtCore/QCoreApplication>

#include "Udp.h"

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

	Udp	udp;
	udp.run();

    return a.exec();
}


Udp.h:
======
#ifndef UDP_H
#define UDP_H

#include <QtNetwork>

class Udp : QObject
{
	Q_OBJECT
public:
	Udp();
	void	run();

private slots:
	void gotData();

private:
	QUdpSocket*	udpSocket;
};

#endif

Udp.cpp
=======
#include "Udp.h"

#include <QHostAddress>

#define LISTEN_PORT	5551

Udp::Udp()
: QObject()
{
	udpSocket = new QUdpSocket(this);
	udpSocket->bind(LISTEN_PORT);
	QTextStream out(stdout);
	out << QString("Listening on port: %1\n").arg(LISTEN_PORT);
	out << QString("=======================\n");
}

void Udp::run()
{
	connect(udpSocket, SIGNAL(readyRead()), this, SLOT(gotData()));
}

void Udp::gotData()
{
	while (udpSocket->hasPendingDatagrams())
	{
		QByteArray datagram;
		datagram.resize(udpSocket->pendingDatagramSize());
		
		QHostAddress sender;
		quint16 senderPort;

		udpSocket->readDatagram(datagram.data(), datagram.size(), &sender,
&senderPort);

		QTextStream out(stdout);
		out << QString("Data: %1\t\t\t\tSender: %2\t\tPort: %3\n")
						.arg(datagram.data())
						.arg(sender.toString())
						.arg(senderPort);
	}

}

--
 [ signature omitted ] 

Message 2 in thread

If you are on Windows, check your personal firewall settings.

Volker


"Patrick Feistel" <Patrick.Feistel@xxxxxxxxxxxxxxxx> wrote in message 
news:ecu7hh$qp0$1@xxxxxxxxxxxxxxxxxxxxx
> Hello,
>
> I have a small Qt4 program which listens on Port 5551 Udp and should
> print out received data to the console.
> I'm sending Udp data from a PPC and a Java program and wireshark can
> receive this data.
> When I'm debugging my Qt-app I see that my app is never reaching the
> SLOT where to process the Udp data, so I think the SIGNAL readyRead() is
> never send out.
> Where is the problem, that I cannot recieve Udp data???
>
> Regards,
>
> Patrick
>
> -------------------------------------------------------------------------
>
> main.cpp:
> =========
> #include <QtCore/QCoreApplication>
>
> #include "Udp.h"
>
> int main(int argc, char *argv[])
> {
>    QCoreApplication a(argc, argv);
>
> Udp udp;
> udp.run();
>
>    return a.exec();
> }
>
>
> Udp.h:
> ======
> #ifndef UDP_H
> #define UDP_H
>
> #include <QtNetwork>
>
> class Udp : QObject
> {
> Q_OBJECT
> public:
> Udp();
> void run();
>
> private slots:
> void gotData();
>
> private:
> QUdpSocket* udpSocket;
> };
>
> #endif
>
> Udp.cpp
> =======
> #include "Udp.h"
>
> #include <QHostAddress>
>
> #define LISTEN_PORT 5551
>
> Udp::Udp()
> : QObject()
> {
> udpSocket = new QUdpSocket(this);
> udpSocket->bind(LISTEN_PORT);
> QTextStream out(stdout);
> out << QString("Listening on port: %1\n").arg(LISTEN_PORT);
> out << QString("=======================\n");
> }
>
> void Udp::run()
> {
> connect(udpSocket, SIGNAL(readyRead()), this, SLOT(gotData()));
> }
>
> void Udp::gotData()
> {
> while (udpSocket->hasPendingDatagrams())
> {
> QByteArray datagram;
> datagram.resize(udpSocket->pendingDatagramSize());
>
> QHostAddress sender;
> quint16 senderPort;
>
> udpSocket->readDatagram(datagram.data(), datagram.size(), &sender,
> &senderPort);
>
> QTextStream out(stdout);
> out << QString("Data: %1\t\t\t\tSender: %2\t\tPort: %3\n")
> .arg(datagram.data())
> .arg(sender.toString())
> .arg(senderPort);
> }
>
> } 


--
 [ signature omitted ] 

Message 3 in thread

Volker Hilsheimer schrieb:
> If you are on Windows, check your personal firewall settings.
> 
> Volker
> 
> 
> "Patrick Feistel" <Patrick.Feistel@xxxxxxxxxxxxxxxx> wrote in message 
> news:ecu7hh$qp0$1@xxxxxxxxxxxxxxxxxxxxx
>> Hello,
>>
>> I have a small Qt4 program which listens on Port 5551 Udp and should
>> print out received data to the console.
>> I'm sending Udp data from a PPC and a Java program and wireshark can
>> receive this data.
>> When I'm debugging my Qt-app I see that my app is never reaching the
>> SLOT where to process the Udp data, so I think the SIGNAL readyRead() is
>> never send out.
>> Where is the problem, that I cannot recieve Udp data???
>>
>> Regards,
>>
>> Patrick
>>
>> -------------------------------------------------------------------------
>>
>> main.cpp:
>> =========
>> #include <QtCore/QCoreApplication>
>>
>> #include "Udp.h"
>>
>> int main(int argc, char *argv[])
>> {
>>    QCoreApplication a(argc, argv);
>>
>> Udp udp;
>> udp.run();
>>
>>    return a.exec();
>> }
>>
>>
>> Udp.h:
>> ======
>> #ifndef UDP_H
>> #define UDP_H
>>
>> #include <QtNetwork>
>>
>> class Udp : QObject
>> {
>> Q_OBJECT
>> public:
>> Udp();
>> void run();
>>
>> private slots:
>> void gotData();
>>
>> private:
>> QUdpSocket* udpSocket;
>> };
>>
>> #endif
>>
>> Udp.cpp
>> =======
>> #include "Udp.h"
>>
>> #include <QHostAddress>
>>
>> #define LISTEN_PORT 5551
>>
>> Udp::Udp()
>> : QObject()
>> {
>> udpSocket = new QUdpSocket(this);
>> udpSocket->bind(LISTEN_PORT);
>> QTextStream out(stdout);
>> out << QString("Listening on port: %1\n").arg(LISTEN_PORT);
>> out << QString("=======================\n");
>> }
>>
>> void Udp::run()
>> {
>> connect(udpSocket, SIGNAL(readyRead()), this, SLOT(gotData()));
>> }
>>
>> void Udp::gotData()
>> {
>> while (udpSocket->hasPendingDatagrams())
>> {
>> QByteArray datagram;
>> datagram.resize(udpSocket->pendingDatagramSize());
>>
>> QHostAddress sender;
>> quint16 senderPort;
>>
>> udpSocket->readDatagram(datagram.data(), datagram.size(), &sender,
>> &senderPort);
>>
>> QTextStream out(stdout);
>> out << QString("Data: %1\t\t\t\tSender: %2\t\tPort: %3\n")
>> .arg(datagram.data())
>> .arg(sender.toString())
>> .arg(senderPort);
>> }
>>
>> } 
> 
> 
Hallo,
my firewall is disabled and other programms listening on this prot are
working, except these using the Qt-classes.
I've tested them seperately and not all at the same time, because that
cannot work.

Regards, Patrick

--
 [ signature omitted ]