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. [SOLVED] Need help to unbind socket connection!
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Need help to unbind socket connection!

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 6.7k 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.
  • J Offline
    J Offline
    jediengineer
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jediengineer
      wrote on last edited by
      #2

      Nevermind, found the solution.

      @udpSocket->close();@

      Worked perfectly.

      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