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. DHCP vs TCP connection
Forum Updated to NodeBB v4.3 + New Features

DHCP vs TCP connection

Scheduled Pinned Locked Moved General and Desktop
11 Posts 4 Posters 3.2k 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.
  • N Offline
    N Offline
    newbie_me
    wrote on last edited by
    #1

    What happens when I establish connection between tcpserver and tcpsocket, and computer's ip will change?
    I guess that will break a connection. Am I right?
    How can I protect connection from breaking in that case?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      QTcpSocket will notify you when the connection is lost. You then need to reconnect.

      (Z(:^

      1 Reply Last reply
      0
      • N Offline
        N Offline
        newbie_me
        wrote on last edited by
        #3

        By "disconnected" or "stateChanged" right, but what's next?
        How can I tell it is connection lost apart intentional close of one program?
        And what's more important, how to find new address to connect with?

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          QTcpSocket send a signal when there is an error or the connection state is changed. You can connect your slot to it and react there.

          As for the IP: I guess it is only your client that can change the IP, right? The server's IP should remain static. So you need to reconnect from the client to the same address it used in the first place.

          If that is not the case, you need to implement some other way of address discovery.

          (Z(:^

          1 Reply Last reply
          0
          • N Offline
            N Offline
            newbie_me
            wrote on last edited by
            #5

            Both works in the same network, so I guess both can change IP.

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              How do you connect them in the first place, then? You have to have a way of finding out the IP.

              In a single LAN network, you can use simple UDP broadcast messages to help peers automatically discover the server.

              Or you could create a local DNS and give your server a name, but that is much harder to do.

              (Z(:^

              1 Reply Last reply
              0
              • N Offline
                N Offline
                newbie_me
                wrote on last edited by
                #7

                I'm connecting them manually (entering right ip).

                UDP doesn't sound like good option cuz connection need to be authorized.

                1 Reply Last reply
                0
                • sierdzioS Offline
                  sierdzioS Offline
                  sierdzio
                  Moderators
                  wrote on last edited by
                  #8

                  This is just an UDP ping saying "I'm the server and this is my IP". Once you have it, you can connect securely using TCP like you do right now.

                  That is just a proven idea, anyway. Feel free to use some other approach if you want to.

                  (Z(:^

                  1 Reply Last reply
                  0
                  • N Offline
                    N Offline
                    newbie_me
                    wrote on last edited by
                    #9

                    Oh, didn't thought about something like this.
                    It actually may be a good solution.
                    Thanks.

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      Ducky
                      wrote on last edited by
                      #10

                      I all depends on how your network is setup.

                      There are two way's of protecting that you have the same ip.

                      1. set your ip fix on your network controller.
                      2. make a reservation on your DHCP server.

                      the difference between TCP an UDP is.

                      If a TCP packet fails it will be re transmitted on UDP packed it wil be not re transmitted.

                      Well I used to write code in Autoit and work on Windows.
                      And now i am trying to write code in QT and work on Ubuntu

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        Hi,

                        Depending on your setup, use zeroconf might also be a possibility to simplify that task.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        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