Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved How to get the address of server dynamically?

    General and Desktop
    6
    9
    4606
    Loading More Posts
    • 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.
    • C
      codeartist last edited by

      Let suppose I have a server installed on computer A. It's listening through QHostAddress::Any on port 8888.

      I have provided a client copy to users. On it's login page I want them to get connected to server which is connected through wifi. so can anyone please tell me how to get that IP address of Server. Is there any function or anything that I can use.

       ************CODE-ARTIST************
      
      1 Reply Last reply Reply Quote 0
      • K
        koahnig last edited by

        Did you try "serverAddress":http://qt-project.org/doc/qt-4.8/qtcpserver.html#serverAddress ?

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply Reply Quote 0
        • C
          codeartist last edited by

          I want my client to know about that :)

           ************CODE-ARTIST************
          
          1 Reply Last reply Reply Quote 0
          • L
            lgeyer last edited by

            You will have to use a service discovery protocol like SSDP or Zeroconf (aka. Bonjour or Avahi). There are no implementations in Qt for this out-of-the-box, but you can use for example the "QxtZeroconf module":http://libqxt.bitbucket.org/doc/0.6/qxtzeroconf.html.

            1 Reply Last reply Reply Quote 1
            • S
              shanek last edited by

              If you're connecting via a host name, you can find out the IP address after connecting using http://doc-snapshot.qt-project.org/5.0/qabstractsocket.html#peerAddress

              If you are talking about discovering a server on a LAN, do what Lukas said or use UDP multicast/broadcast.
              If you are talking about discovering a server on the internet, then you need a master server with a DNS name somewhere.

              1 Reply Last reply Reply Quote 0
              • C
                codeartist last edited by

                Thanks for the reply guys! I am trying to do this :)

                 ************CODE-ARTIST************
                
                1 Reply Last reply Reply Quote 0
                • V
                  vezprog last edited by

                  1. On your client side create a QTcpSocket and a QUdpSocket and on the server side create a QTcpServer and a QUdpSocket.
                  2. On the client, send out a broadcast message saying "who is out there, i am a client"
                  3. Once the packet is received on the server, send a direct UDP packet back to the QUdpSocket saying "i am here, pick me this is my tcp ip address and tcp port" (you can get the address and port from the received packet). I usually populate a QListView with the ipaddress and ports so that user can choose who he wants to connect to.
                  4. When your ready to connect, just take the tcp address and port sent in the packet and connect the QTcpSocket to the QTcpServer.

                  It's basically your standard SSDP as was stated above.

                  Good Luck!

                  1 Reply Last reply Reply Quote 2
                  • C
                    codeartist last edited by

                    Thanks! It worked! :)

                     ************CODE-ARTIST************
                    
                    1 Reply Last reply Reply Quote 0
                    • V
                      Vicky Sharma last edited by Vicky Sharma

                      yes your idea working..
                      thanks :)

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post