PDA

View Full Version : UDP - QUdpSocket



denwelzie
23rd April 2008, 08:26
Using Qt 4.3.1 on Win Xp.

I have set up QUdpSocket in a Qt GUI application that reads datagrams over a socket bound to my local port.

udpSocket_.bind(udpPort, QUdpSocket::DefaultForPlatform)

The QUdpSocket::DefaultForPlatform argument is documented as being the equivalent to SharedAddress on Windows.This application only receives datagrams via the UDP connection. Its code is near identical to hasPendingDatagrams then readDatagram code found in the Assistant documentation.

I have written another Qt GUI application for testing my main application. This application sends timed datagrams for the main application to read in. Once again the code is similar to that found in the Assistant documentation.

Nothing flash at all!

Both these Qt applications run on the same machine. So what I am trying to do is run my main application, then the test application that sends UDP datagrams to the main application. The main application is then meant to signal a readyRead and run the SLOT handler.

Ok its not running for me, both applications use the same udpPort!

Any help would be appreciated :):)

wysota
23rd April 2008, 09:15
You can't use the same IP-port pair or else your applications will get confused. In particular they will be receving their own datagrams.

denwelzie
24th April 2008, 02:18
In a sense this is almost what I am trying to achieve!

Ok I think I should not have referred to one of my applications as the main application ….. so I will call it Application 1 and my test application, Application 2.

Application 1 can only receive datagrams and Application 2 can only send datagrams!

In Application 1 I have set up a UDP socketed connection and a handler that fires on a readyRead() signal …. This is what I am trying to test.

My teat Application 2 that runs on the same PC is another Qt GUI that does other stuff but on the click of a button will desirably send datagrams at predefined time intervals to Application 1 ……….. so this is why I have bound them to the same socket to try to get them talking to each other.

I hope I have been clearer and thanks for your prompt reply and help

wysota
24th April 2008, 10:05
If they are running on the same machine, what's the point of using network sockets? Use some pipe, shared memory or some other IPC mechanism.

denwelzie
28th April 2008, 09:20
The point is I wish to test my handling of UDP datagrams in an application that in the real world will run on a remote machine receiving the data messages from some remote source. So this application will only ever receive messages.

The second application that I wish to send datagrams is a TEST application only that for convenience sake I wish to run off the same machine. Its like a test spike that is intended to send to send a pre structured message that when handled I can analyse the output for correctness.

A form off loopback test so I just need to figure out how to look back the bound UDP port!

The test application is not going to be used by anyone but me.

I hope this is clearer :)

wysota
28th April 2008, 09:41
The point is I wish to test my handling of UDP datagrams in an application that in the real world will run on a remote machine receiving the data messages from some remote source. So this application will only ever receive messages.

The second application that I wish to send datagrams is a TEST application only that for convenience sake I wish to run off the same machine. Its like a test spike that is intended to send to send a pre structured message that when handled I can analyse the output for correctness.
What if there are two instances of the system running across the same two hosts? Don't you think it is better to use different port numbers? Even just for testing? You can actually configure the port number, you know :)

denwelzie
29th April 2008, 02:48
Yeah Ive tried that and its still giving me grief :mad::mad:

wysota
29th April 2008, 10:02
What exactly happens? Maybe the firewall is blocking access to those ports? Also compile your app with console support activated and check if Qt gives you any warnings about non-existing signals or slots.