QUdpSocket bind



  • 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



  • 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]



  • 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 ?



  • 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



  • 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.



  • 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/


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.