Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QUdpSocket bind
Forum Updated to NodeBB v4.3 + New Features

QUdpSocket bind

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 9.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • clogwogC Offline
    clogwogC Offline
    clogwog
    wrote on last edited by
    #1

    A few of the QUdpSocket server samples i have seen use the following call to bind:

    myUdpSocket->bind(QHostAddress("127.0.0.1"), 1234, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint);

    Does that mean that you can have multiple applications on the same machine that can open a UDP listning socket ?
    so if a client does a broadcast, both applications will receive the broadcast (on port 1234 ) ?

    I'm just asking because i know it's not possible to open multiple TCP server sockets on the same machine-interface-port combination.
    When i did a search on this forum someone said that it's also not possible with UDP Sockets.. (the example however didn't have the QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint options set though )

    thanks,
    tom

    1 Reply Last reply
    0
    • C Offline
      C Offline
      changsheng230
      wrote on last edited by
      #2

      My answer is YES, both app will receive the broadcast. I double conform this using the example $QTDIR\Examples\4.7\network\broadcastreceiver and update the flag from QUdpSocket::ShareAddress to QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint

      [quote author="clogwog" date="1310514627"]

      Does that mean that you can have multiple applications on the same machine that can open a UDP listning socket ?
      so if a client does a broadcast, both applications will receive the broadcast (on port 1234 ) ?

      [/quote]

      Chang Sheng
      常升

      1 Reply Last reply
      0
      • clogwogC Offline
        clogwogC Offline
        clogwog
        wrote on last edited by
        #3

        thank you for looking at that. i was just making sure i wasn't making any false presumptions.

        i'm seeing some weird behavior using that model, and i'm not sure where the problem lies.

        if i start-up 1 server application that listens to incoming Udp packets (that are broadcast) it all works fine.

        when i start-up a second app that also listens to incoming Udp packets (on the same port), it seems to take over from the first application. It's as if the application 'consumes' the packets and the 1st app never sees them.

        when i then close the second application, the first application starts receiving Udp packets again..

        does the readDatagram() function do something like that ?

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jena43
          wrote on last edited by
          #4

          Hello clogwog,

          I know this is an old question, but I have the same problem here...
          I have one server which sends data through a given port (3333) on localhost via UDP.
          I have a localhost client which listens the data coming from the port 3333 using QUdpSocket.
          When I run one instance of my client, it works just fine.
          When I run a second instance, the second instance never gets the readyread() signal, but the first one is ok.
          When I quit the first instance, the second finally gets the readyRead() signal and data.

          I need to have many instances of my client code running on the same machine, and binded to the same port.

          What should I do ?

          Using Qt5.3.1 on Win7-64b
          Thanks

          1 Reply Last reply
          0
          • clogwogC Offline
            clogwogC Offline
            clogwog
            wrote on last edited by
            #5

            This is not going to help you because i have a limited number of applications i ended up sending it to each individually on different ports instead of relying on the 'broadcast'

            sorry i can't help

            i assume you have the QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint options on the listening socket.

            1 Reply Last reply
            0
            • J Offline
              J Offline
              Jena43
              wrote on last edited by
              #6

              Yes, I have set these flags while binding the client socket...

              Thanks for your answer anyway, I think I'm going to open a new thread for my question.

              EDIT : "thread opened #44601":http://qt-project.org/forums/viewthread/44601/

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved