Results 1 to 8 of 8

Thread: UDP - QUdpSocket

  1. #1
    Join Date
    Apr 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default UDP - QUdpSocket

    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:efaultForPlatform)

    The QUdpSocket:efaultForPlatform 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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: UDP - QUdpSocket

    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.

  3. #3
    Join Date
    Apr 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: UDP - QUdpSocket

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: UDP - QUdpSocket

    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.

  5. #5
    Join Date
    Apr 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: UDP - QUdpSocket

    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

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: UDP - QUdpSocket

    Quote Originally Posted by denwelzie View Post
    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

  7. #7
    Join Date
    Apr 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: UDP - QUdpSocket

    Yeah Ive tried that and its still giving me grief

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: UDP - QUdpSocket

    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.

Similar Threads

  1. QUdpSocket binding
    By db in forum Qt Programming
    Replies: 0
    Last Post: 13th March 2008, 11:24
  2. Using QUdpSocket within a QThread
    By db in forum Newbie
    Replies: 18
    Last Post: 30th October 2007, 23:59
  3. QUdpSocket bind / connectToHost ?
    By mnemonic_fx in forum Newbie
    Replies: 2
    Last Post: 17th July 2007, 03:20
  4. QUdpSocket and ShareAddress
    By mdecandia in forum Qt Programming
    Replies: 5
    Last Post: 26th March 2007, 17:06
  5. QUdpSocket hasPendingDatagrams()
    By mbjerkne in forum Qt Programming
    Replies: 3
    Last Post: 4th April 2006, 19:14

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.