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. How to get the address of server dynamically?

How to get the address of server dynamically?

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 6 Posters 5.0k Views
  • 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 Offline
    C Offline
    codeartist
    wrote on last edited by
    #1

    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
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      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
      0
      • C Offline
        C Offline
        codeartist
        wrote on last edited by
        #3

        I want my client to know about that :)

         ************CODE-ARTIST************
        
        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #4

          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
          1
          • S Offline
            S Offline
            shanek
            wrote on last edited by
            #5

            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
            0
            • C Offline
              C Offline
              codeartist
              wrote on last edited by
              #6

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

               ************CODE-ARTIST************
              
              1 Reply Last reply
              0
              • V Offline
                V Offline
                vezprog
                wrote on last edited by
                #7
                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
                2
                • C Offline
                  C Offline
                  codeartist
                  wrote on last edited by
                  #8

                  Thanks! It worked! :)

                   ************CODE-ARTIST************
                  
                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    Vicky Sharma
                    wrote on last edited by Vicky Sharma
                    #9

                    yes your idea working..
                    thanks :)

                    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