[SOLVED] Need help to unbind socket connection!



  • Hi All, my program has the following code to find the IPV4 address and bind my socket connection to it:

    @
    foreach(QNetworkInterface interface,
    QNetworkInterface::allInterfaces())
    {
    if (interface.flags().testFlag(QNetworkInterface::IsUp) && (!interface.flags().testFlag(QNetworkInterface::IsLoopBack)))
    {
    foreach(QNetworkAddressEntry entry,
    interface.addressEntries())
    {
    if ((entry.ip().protocol() == QAbstractSocket::IPv4Protocol) && !IP_is_set)
    {
    local_IPv4 = entry.ip().toString();

                    udpSocket->bind(QHostAddress(QString (local_IPv4)), host_port);
                    connect(udpSocket, SIGNAL(readyRead()), this, SLOT(readPendingDatagram()));
    
                    IP_is_set = true;
                }
            }
        }
    }
    

    @

    However, it often times occurs when the DHCP server screws something up, or windows gets lost in it's own mess, and you need to release and renew the windows socket connection. Sometimes the DHCP server on your switch will assign a new IP address to your computer. So I guess my question is really 2 questions:

    What happens if my function is run again as is - does it overwrite the connection parameters and/or cause a problem?

    Do I need to unbind and disconnect the socket connection before I can bind the new IP address to that socket? If so, I'm not sure how to go about that - not too experienced qith Qt's methods yet....

    Thanks!



  • Nevermind, found the solution.

    @udpSocket->close();@

    Worked perfectly.


Log in to reply
 

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