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. Connect to non-local IP or domain name
Forum Updated to NodeBB v4.3 + New Features

Connect to non-local IP or domain name

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 4 Posters 2.6k 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.
  • I Offline
    I Offline
    isan
    wrote on 16 Jun 2018, 10:42 last edited by
    #1

    I have 2 question
    1-if I want to connect to non-local IP with QTcp Socket ,what should I do ?

    QHostAddress address ("172.20.10.151");
        _socket->connectToHost(address,8585);
    

    I use this to connect to the local IP ,but what to use if non-local IP?
    If IP is not within my IP range,what should we do?
    for example my IP is 172.20.10.100
    and the server IP is 192.168.1.240
    f I have domain name can use this?

    QHostAddress address ("mydomainName.com");
        _socket->connectToHost(address,port);
    

    2-If I want to connect to sqlserver that it in non-local ,what should I do ?

    db = QSqlDatabase::addDatabase("QODBC");
        bool test=db.isValid();//true
        test=db.isDriverAvailable("QODBC");//true
        db.setHostName("localhost\\SQLSERVER");
        db.setDatabaseName("DRIVER={SQL Server};SERVER=localhost\\SQLSERVER;DATABASE=DB1");
    

    I use this to connect to a local database, but what should I do if the IP is non-local?
    What if the IP is not within my IP range?
    What should I do?
    What if the database address is a domain name?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 16 Jun 2018, 11:59 last edited by mrjj
      #2

      Hi
      To connect a server, the firewalls need to allow it.
      So the routers and switches will route your incoming connections to the right pc.
      Even if you are not on same subnet.
      So it will just work if the infrastructure allows it.

      A domain name is merely a human readable version of an ip.
      so makes no difference.
      you always really connect to an IP and a port.
      often the port is determined by the protocol. Like 80 for http etc.

      You will connect to an IP and port and if database server is behind a firewall,
      it must allow that traffic.

      I 1 Reply Last reply 16 Jun 2018, 15:17
      4
      • M mrjj
        16 Jun 2018, 11:59

        Hi
        To connect a server, the firewalls need to allow it.
        So the routers and switches will route your incoming connections to the right pc.
        Even if you are not on same subnet.
        So it will just work if the infrastructure allows it.

        A domain name is merely a human readable version of an ip.
        so makes no difference.
        you always really connect to an IP and a port.
        often the port is determined by the protocol. Like 80 for http etc.

        You will connect to an IP and port and if database server is behind a firewall,
        it must allow that traffic.

        I Offline
        I Offline
        isan
        wrote on 16 Jun 2018, 15:17 last edited by
        #3

        @mrjj So this code works without modification, If ip remotely allows me to connect?
        I do not need to change the code or make a custom setting on the client device?

        1 Reply Last reply
        0
        • K Offline
          K Offline
          KillerSmath
          wrote on 16 Jun 2018, 18:04 last edited by
          #4

          @isan

          The network modules works with intra and extra network acess. But the responsable to forward your connection if necessary is the gateway of your network.

          A little resume of how network communication works:

          If the IP A and B are in the same network, A will send directly the packet to B because they are in the same network.
          But if the IP A and B are in different network, A will send the packet to default gateway of network and the gateway will be the responsable to find the next route to send the packet to B and so on until the packet reaches the destination or be discarded.

          But the communation can be refused for n reasons:

          • The gateway don't know how forward the connection (next route)
          • The gateway can refuse connection for a specific ip of network
          • The firewall can deny the connetion, etc.

          So, notice that it is a infraestruture problem and not a software problem.

          @Computer Science Student - Brazil
          Web Developer and Researcher
          “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

          1 Reply Last reply
          5
          • M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 16 Jun 2018, 19:20 last edited by
            #5

            On top of @KillerSmath good explanation, i can highly recommend to read some
            networking to have an overview of how it works.
            http://www.steves-internet-guide.com/basic-networking-course/

            I 1 Reply Last reply 27 Jun 2018, 10:47
            3
            • M mrjj
              16 Jun 2018, 19:20

              On top of @KillerSmath good explanation, i can highly recommend to read some
              networking to have an overview of how it works.
              http://www.steves-internet-guide.com/basic-networking-course/

              I Offline
              I Offline
              isan
              wrote on 27 Jun 2018, 10:47 last edited by
              #6

              @mrjj so whats difference between network and websockets module?
              for connect to web server or non-local IP should use witch one?

              M 1 Reply Last reply 27 Jun 2018, 15:45
              0
              • I isan
                27 Jun 2018, 10:47

                @mrjj so whats difference between network and websockets module?
                for connect to web server or non-local IP should use witch one?

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 27 Jun 2018, 15:45 last edited by mrjj
                #7

                Hi
                Websockets is a protocol designed for 2 ways interaction with
                web servers.
                Where as the network classes are more generic/broad to talk to any kind of
                IP device.

                To talk to an non local database server, you would still use the SQL classes.
                It really dont matter if local or on global scrope. Still works the same except
                there will be firewall in front if outside.
                Often if you buy the database access as service, its already set up to allow connections.
                If you own server. you need to make it possible.

                I 1 Reply Last reply 28 Jun 2018, 14:51
                3
                • M mrjj
                  27 Jun 2018, 15:45

                  Hi
                  Websockets is a protocol designed for 2 ways interaction with
                  web servers.
                  Where as the network classes are more generic/broad to talk to any kind of
                  IP device.

                  To talk to an non local database server, you would still use the SQL classes.
                  It really dont matter if local or on global scrope. Still works the same except
                  there will be firewall in front if outside.
                  Often if you buy the database access as service, its already set up to allow connections.
                  If you own server. you need to make it possible.

                  I Offline
                  I Offline
                  isan
                  wrote on 28 Jun 2018, 14:51 last edited by isan
                  #8

                  @mrjj So If I want to connect to web server , can I use network module?

                  jsulmJ 1 Reply Last reply 29 Jun 2018, 05:19
                  0
                  • K Offline
                    K Offline
                    KillerSmath
                    wrote on 28 Jun 2018, 19:16 last edited by KillerSmath
                    #9

                    @isan
                    If you are trying to connect to SqlServer database using tcp ip, you can find an explanation in the ODBC Qt Wiki:
                    Open Connection using TCP/IP

                    Remember: The firewall of your server needs to allow the connection by port or service or it will deny the connection.

                    @Computer Science Student - Brazil
                    Web Developer and Researcher
                    “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

                    1 Reply Last reply
                    3
                    • I isan
                      28 Jun 2018, 14:51

                      @mrjj So If I want to connect to web server , can I use network module?

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on 29 Jun 2018, 05:19 last edited by
                      #10

                      @isan Above you wanted to connect to a SQL server, now to a web server. So, what do you really want to do?

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      I 1 Reply Last reply 30 Jun 2018, 14:17
                      2
                      • jsulmJ jsulm
                        29 Jun 2018, 05:19

                        @isan Above you wanted to connect to a SQL server, now to a web server. So, what do you really want to do?

                        I Offline
                        I Offline
                        isan
                        wrote on 30 Jun 2018, 14:17 last edited by
                        #11

                        @jsulm I Had two different question on first ,non-local IP can be anything

                        M 1 Reply Last reply 30 Jun 2018, 14:35
                        0
                        • I isan
                          30 Jun 2018, 14:17

                          @jsulm I Had two different question on first ,non-local IP can be anything

                          M Offline
                          M Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 30 Jun 2018, 14:35 last edited by
                          #12

                          @isan
                          Hi
                          Yes you can use the network module to talk to web server.
                          Here is sample that downloads a file
                          http://www.bogotobogo.com/Qt/Qt5_Downloading_Files_QNetworkAccessManager_QNetworkRequest.php

                          so rest depends on WHAT you want to do with the web server.

                          I 1 Reply Last reply 30 Jun 2018, 19:32
                          3
                          • M mrjj
                            30 Jun 2018, 14:35

                            @isan
                            Hi
                            Yes you can use the network module to talk to web server.
                            Here is sample that downloads a file
                            http://www.bogotobogo.com/Qt/Qt5_Downloading_Files_QNetworkAccessManager_QNetworkRequest.php

                            so rest depends on WHAT you want to do with the web server.

                            I Offline
                            I Offline
                            isan
                            wrote on 30 Jun 2018, 19:32 last edited by
                            #13

                            @mrjj thank you so much

                            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