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. QTcpSocket connecting even tho no server?

QTcpSocket connecting even tho no server?

Scheduled Pinned Locked Moved Unsolved General and Desktop
28 Posts 7 Posters 5.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.
  • J.HilkJ J.Hilk

    @SPlatten isOpen() is from the very base QIODevice class, I'm not sure when exactly this is set.

    What you should be looking for in your QTcpSocket instance, is state() and wether or not that is QAbstractSocket::ConnectedState

    SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #3

    @J-Hilk , thank you, I've changed the code to:

    void clsMsgSender::onStartService() {
    qdbg() << mpsckClient->state();
        if ( mpsckClient->state() != QAbstractSocket::ConnectedState ) {
        //Change connection interval to regular connection time period for reconnects
            mptmrConnect->setInterval(clsMsgSender::mscuint16ConnectTimer);
        //Get local IP address
            QString strIP = clsMsgSender::strGetLocalIP();
            qdbg() << "Connecting to: " << strIP << ":" << muint16Port;
        //Connect to the Application
            mpsckClient->connectToHost(strIP, muint16Port);
        }
        if ( clsMsgSender::mspThread == nullptr ) {
            clsMsgSender::mspThread = new QThread;
            moveToThread(clsMsgSender::mspThread);
            QObject::connect(clsMsgSender::mspThread, &QThread::started
                        ,this, &clsMsgSender::run);
            QObject::connect(this, &clsMsgSender::finished
                        ,clsMsgSender::mspThread, &QThread::quit);
        }
        if ( mqueMsgsOut.size() > 0 && clsMsgSender::mspThread != nullptr ) {
            clsMsgSender::mspThread->start();
        }
    }
    

    I've also added a connection to:

    QObject::connect(mpsckClient, &QTcpSocket::hostFound
                        ,this, &clsMsgSender::onHostFound);
    

    In my onHostFound slot:

    void clsMsgSender::onHostFound() {
       qdbg() << "Host Found!";
    }
    

    From the Application Output I can see lots of Host Found! messages, is this normal when the IP:Port doesn't have anything listening to it?

    Kind Regards,
    Sy

    O KroMignonK 2 Replies Last reply
    0
    • SPlattenS SPlatten

      @J-Hilk , thank you, I've changed the code to:

      void clsMsgSender::onStartService() {
      qdbg() << mpsckClient->state();
          if ( mpsckClient->state() != QAbstractSocket::ConnectedState ) {
          //Change connection interval to regular connection time period for reconnects
              mptmrConnect->setInterval(clsMsgSender::mscuint16ConnectTimer);
          //Get local IP address
              QString strIP = clsMsgSender::strGetLocalIP();
              qdbg() << "Connecting to: " << strIP << ":" << muint16Port;
          //Connect to the Application
              mpsckClient->connectToHost(strIP, muint16Port);
          }
          if ( clsMsgSender::mspThread == nullptr ) {
              clsMsgSender::mspThread = new QThread;
              moveToThread(clsMsgSender::mspThread);
              QObject::connect(clsMsgSender::mspThread, &QThread::started
                          ,this, &clsMsgSender::run);
              QObject::connect(this, &clsMsgSender::finished
                          ,clsMsgSender::mspThread, &QThread::quit);
          }
          if ( mqueMsgsOut.size() > 0 && clsMsgSender::mspThread != nullptr ) {
              clsMsgSender::mspThread->start();
          }
      }
      

      I've also added a connection to:

      QObject::connect(mpsckClient, &QTcpSocket::hostFound
                          ,this, &clsMsgSender::onHostFound);
      

      In my onHostFound slot:

      void clsMsgSender::onHostFound() {
         qdbg() << "Host Found!";
      }
      

      From the Application Output I can see lots of Host Found! messages, is this normal when the IP:Port doesn't have anything listening to it?

      O Offline
      O Offline
      ollarch
      wrote on last edited by
      #4

      @SPlatten said in QTcpSocket connecting even tho no server?:

      From the Application Output I can see lots of Host Found! messages, is this normal when the IP:Port doesn't have anything listening to it?

      But the host if found. The problem will be if the localhost is not found. One thing is that it found the host and the other thing is that there is some process linstening on the port.

      SPlattenS 1 Reply Last reply
      2
      • O ollarch

        @SPlatten said in QTcpSocket connecting even tho no server?:

        From the Application Output I can see lots of Host Found! messages, is this normal when the IP:Port doesn't have anything listening to it?

        But the host if found. The problem will be if the localhost is not found. One thing is that it found the host and the other thing is that there is some process linstening on the port.

        SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on last edited by
        #5

        @ollarch , the IP exists on the system, but there is no application running listening for connection, nothing is using that port.

        Kind Regards,
        Sy

        J.HilkJ O 2 Replies Last reply
        0
        • SPlattenS SPlatten

          @J-Hilk , thank you, I've changed the code to:

          void clsMsgSender::onStartService() {
          qdbg() << mpsckClient->state();
              if ( mpsckClient->state() != QAbstractSocket::ConnectedState ) {
              //Change connection interval to regular connection time period for reconnects
                  mptmrConnect->setInterval(clsMsgSender::mscuint16ConnectTimer);
              //Get local IP address
                  QString strIP = clsMsgSender::strGetLocalIP();
                  qdbg() << "Connecting to: " << strIP << ":" << muint16Port;
              //Connect to the Application
                  mpsckClient->connectToHost(strIP, muint16Port);
              }
              if ( clsMsgSender::mspThread == nullptr ) {
                  clsMsgSender::mspThread = new QThread;
                  moveToThread(clsMsgSender::mspThread);
                  QObject::connect(clsMsgSender::mspThread, &QThread::started
                              ,this, &clsMsgSender::run);
                  QObject::connect(this, &clsMsgSender::finished
                              ,clsMsgSender::mspThread, &QThread::quit);
              }
              if ( mqueMsgsOut.size() > 0 && clsMsgSender::mspThread != nullptr ) {
                  clsMsgSender::mspThread->start();
              }
          }
          

          I've also added a connection to:

          QObject::connect(mpsckClient, &QTcpSocket::hostFound
                              ,this, &clsMsgSender::onHostFound);
          

          In my onHostFound slot:

          void clsMsgSender::onHostFound() {
             qdbg() << "Host Found!";
          }
          

          From the Application Output I can see lots of Host Found! messages, is this normal when the IP:Port doesn't have anything listening to it?

          KroMignonK Offline
          KroMignonK Offline
          KroMignon
          wrote on last edited by KroMignon
          #6

          @SPlatten said in QTcpSocket connecting even tho no server?:

          From the Application Output I can see lots of Host Found! messages, is this normal when the IP:Port doesn't have anything listening to it?

          Why do you never read documentation before asking what already describe in documentation?
          Have you tried to read connectToHost() documentation (hint: just hit F1 key in Qt Creator):

          Attempts to make a connection to hostName on the given port. The protocol parameter can be used to specify which network protocol to use (eg. IPv4 or IPv6).

          The socket is opened in the given openMode and first enters HostLookupState, then performs a host name lookup of hostName. If the lookup succeeds, hostFound() is emitted and QAbstractSocket enters ConnectingState. It then attempts to connect to the address or addresses returned by the lookup. Finally, if a connection is established, QAbstractSocket enters ConnectedState and emits connected().

          At any point, the socket can emit errorOccurred() to signal that an error occurred.

          hostName may be an IP address in string form (e.g., "43.195.83.32"), or it may be a host name (e.g., "example.com"). QAbstractSocket will do a lookup only if required. port is in native byte order.

          As you could read:

          • the socket is opened, so QTcpSocket::isOpen() will return true
          • hostname lookup is started ==> hostFound() is emitted on success
          • on success, connection is started

          It is so hard to read documentation????

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          SPlattenS 1 Reply Last reply
          6
          • SPlattenS SPlatten

            @ollarch , the IP exists on the system, but there is no application running listening for connection, nothing is using that port.

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #7

            @SPlatten do you call connectToHost multiple times ? IIRC each connectTohost call may emit a HostFound signal


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            SPlattenS 1 Reply Last reply
            0
            • J.HilkJ J.Hilk

              @SPlatten do you call connectToHost multiple times ? IIRC each connectTohost call may emit a HostFound signal

              SPlattenS Offline
              SPlattenS Offline
              SPlatten
              wrote on last edited by
              #8

              @J-Hilk I do call every 5 seconds.

              Kind Regards,
              Sy

              1 Reply Last reply
              0
              • SPlattenS SPlatten

                @ollarch , the IP exists on the system, but there is no application running listening for connection, nothing is using that port.

                O Offline
                O Offline
                ollarch
                wrote on last edited by
                #9

                @SPlatten said in QTcpSocket connecting even tho no server?:

                @ollarch , the IP exists on the system, but there is no application running listening for connection, nothing is using that port.

                So, the host is found.
                As @KroMignon has told you a lot of times is to read the documentation.
                It seems that you write some code, test, and if it fails you start writing a new thread in the forum.
                Yes, I know that you have a lot work to do but this also applies to us.

                SPlattenS 1 Reply Last reply
                5
                • O ollarch

                  @SPlatten said in QTcpSocket connecting even tho no server?:

                  @ollarch , the IP exists on the system, but there is no application running listening for connection, nothing is using that port.

                  So, the host is found.
                  As @KroMignon has told you a lot of times is to read the documentation.
                  It seems that you write some code, test, and if it fails you start writing a new thread in the forum.
                  Yes, I know that you have a lot work to do but this also applies to us.

                  SPlattenS Offline
                  SPlattenS Offline
                  SPlatten
                  wrote on last edited by SPlatten
                  #10

                  @ollarch, I have read the documentation, and nowhere does it say that the hostFound signal is issue when the IP is found regardless of the port!

                  The IP and Port combine make the address, the IP itself is no indication that there is anything to connect to, not if there is nothing using the specified port. And this information is not documented, hence my question.

                  Kind Regards,
                  Sy

                  JonBJ 1 Reply Last reply
                  0
                  • Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #11

                    @SPlatten said in QTcpSocket connecting even tho no server?:

                    and nowhere does it say that the hostFound signal is issue when the IP is found regardless of the port!

                    Sorry but the error is called 'HostNotFound' - not 'Can not connect to host and port'...

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    1 Reply Last reply
                    0
                    • KroMignonK KroMignon

                      @SPlatten said in QTcpSocket connecting even tho no server?:

                      From the Application Output I can see lots of Host Found! messages, is this normal when the IP:Port doesn't have anything listening to it?

                      Why do you never read documentation before asking what already describe in documentation?
                      Have you tried to read connectToHost() documentation (hint: just hit F1 key in Qt Creator):

                      Attempts to make a connection to hostName on the given port. The protocol parameter can be used to specify which network protocol to use (eg. IPv4 or IPv6).

                      The socket is opened in the given openMode and first enters HostLookupState, then performs a host name lookup of hostName. If the lookup succeeds, hostFound() is emitted and QAbstractSocket enters ConnectingState. It then attempts to connect to the address or addresses returned by the lookup. Finally, if a connection is established, QAbstractSocket enters ConnectedState and emits connected().

                      At any point, the socket can emit errorOccurred() to signal that an error occurred.

                      hostName may be an IP address in string form (e.g., "43.195.83.32"), or it may be a host name (e.g., "example.com"). QAbstractSocket will do a lookup only if required. port is in native byte order.

                      As you could read:

                      • the socket is opened, so QTcpSocket::isOpen() will return true
                      • hostname lookup is started ==> hostFound() is emitted on success
                      • on success, connection is started

                      It is so hard to read documentation????

                      SPlattenS Offline
                      SPlattenS Offline
                      SPlatten
                      wrote on last edited by
                      #12

                      @KroMignon , I didn't say I never read the documentation, that's your inference and on this occasion I find that the documentation is not detailed enough. An address has two parts, the IP and the port.

                      Kind Regards,
                      Sy

                      KroMignonK 1 Reply Last reply
                      0
                      • SPlattenS SPlatten

                        @KroMignon , I didn't say I never read the documentation, that's your inference and on this occasion I find that the documentation is not detailed enough. An address has two parts, the IP and the port.

                        KroMignonK Offline
                        KroMignonK Offline
                        KroMignon
                        wrote on last edited by
                        #13

                        @SPlatten said in QTcpSocket connecting even tho no server?:

                        I find that the documentation is not detailed enough. An address has two parts, the IP and the port.

                        It is written in documentation:
                        The socket is opened in the given openMode and first enters HostLookupState, then performs a host name lookup of hostName. If the lookup succeeds, hostFound() is emitted

                        => host name lookup, this is done before connection starts, so no need of TCP port.

                        This is very explicitly described in documentation.

                        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                        1 Reply Last reply
                        6
                        • SPlattenS SPlatten

                          @ollarch, I have read the documentation, and nowhere does it say that the hostFound signal is issue when the IP is found regardless of the port!

                          The IP and Port combine make the address, the IP itself is no indication that there is anything to connect to, not if there is nothing using the specified port. And this information is not documented, hence my question.

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by JonB
                          #14

                          @SPlatten
                          I don't want to get into an argument, but it does say that.

                          https://doc.qt.io/qt-5/qabstractsocket.html#hostFound :

                          This signal is emitted after connectToHost() has been called and the host lookup has succeeded.

                          https://doc.qt.io/qt-5/qabstractsocket.html#connectToHost :

                          The socket is opened in the given openMode and first enters HostLookupState, then performs a host name lookup of hostName. If the lookup succeeds, hostFound() is emitted and QAbstractSocket enters ConnectingState. It then attempts to connect to the address or addresses returned by the lookup. Finally, if a connection is established, QAbstractSocket enters ConnectedState and emits connected().

                          So, as it says, hostFound signal is emitted on finding the host IP address. It does what it says on the packet, i.e. it's just a host lookup, by name or IP address, and tells you the host does exist.

                          Connecting on the port comes after that, and of course may succeed or fail separately.

                          Anyway, there it is, that's how it works.

                          SPlattenS 1 Reply Last reply
                          2
                          • JonBJ JonB

                            @SPlatten
                            I don't want to get into an argument, but it does say that.

                            https://doc.qt.io/qt-5/qabstractsocket.html#hostFound :

                            This signal is emitted after connectToHost() has been called and the host lookup has succeeded.

                            https://doc.qt.io/qt-5/qabstractsocket.html#connectToHost :

                            The socket is opened in the given openMode and first enters HostLookupState, then performs a host name lookup of hostName. If the lookup succeeds, hostFound() is emitted and QAbstractSocket enters ConnectingState. It then attempts to connect to the address or addresses returned by the lookup. Finally, if a connection is established, QAbstractSocket enters ConnectedState and emits connected().

                            So, as it says, hostFound signal is emitted on finding the host IP address. It does what it says on the packet, i.e. it's just a host lookup, by name or IP address, and tells you the host does exist.

                            Connecting on the port comes after that, and of course may succeed or fail separately.

                            Anyway, there it is, that's how it works.

                            SPlattenS Offline
                            SPlattenS Offline
                            SPlatten
                            wrote on last edited by
                            #15

                            @JonB , as I said previously the IP is just part of the address, the port completes the address, when you establish the connection the port is optional, but if supplied then it should be used because connecting to address and address:port are very different.

                            Kind Regards,
                            Sy

                            Christian EhrlicherC JonBJ KroMignonK 3 Replies Last reply
                            0
                            • SPlattenS SPlatten

                              @JonB , as I said previously the IP is just part of the address, the port completes the address, when you establish the connection the port is optional, but if supplied then it should be used because connecting to address and address:port are very different.

                              Christian EhrlicherC Offline
                              Christian EhrlicherC Offline
                              Christian Ehrlicher
                              Lifetime Qt Champion
                              wrote on last edited by
                              #16

                              @SPlatten said in QTcpSocket connecting even tho no server?:

                              address:port

                              This is wrong. It's host:port !

                              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                              Visit the Qt Academy at https://academy.qt.io/catalog

                              SPlattenS 1 Reply Last reply
                              0
                              • Christian EhrlicherC Christian Ehrlicher

                                @SPlatten said in QTcpSocket connecting even tho no server?:

                                address:port

                                This is wrong. It's host:port !

                                SPlattenS Offline
                                SPlattenS Offline
                                SPlatten
                                wrote on last edited by
                                #17

                                @Christian-Ehrlicher , are you being piccy?

                                Kind Regards,
                                Sy

                                1 Reply Last reply
                                0
                                • Christian EhrlicherC Offline
                                  Christian EhrlicherC Offline
                                  Christian Ehrlicher
                                  Lifetime Qt Champion
                                  wrote on last edited by Christian Ehrlicher
                                  #18

                                  @SPlatten said in QTcpSocket connecting even tho no server?:

                                  are you being piccy?

                                  No, but your assumptions are wrong because of this wrong definition.

                                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                  Visit the Qt Academy at https://academy.qt.io/catalog

                                  1 Reply Last reply
                                  0
                                  • SPlattenS SPlatten

                                    @JonB , as I said previously the IP is just part of the address, the port completes the address, when you establish the connection the port is optional, but if supplied then it should be used because connecting to address and address:port are very different.

                                    JonBJ Offline
                                    JonBJ Offline
                                    JonB
                                    wrote on last edited by JonB
                                    #19

                                    @SPlatten
                                    Sorry, Simon, you're incorrect. I did try to explain. I do know what IP addresses vs ports are. I was just pointing out, politely, that Qt's hostFound is emitted on host found, not on port is listening/connected. Anyways, it's not worth arguing about, we were just talking about how Qt documents what it is that it does when.

                                    1 Reply Last reply
                                    2
                                    • SPlattenS SPlatten

                                      @JonB , as I said previously the IP is just part of the address, the port completes the address, when you establish the connection the port is optional, but if supplied then it should be used because connecting to address and address:port are very different.

                                      KroMignonK Offline
                                      KroMignonK Offline
                                      KroMignon
                                      wrote on last edited by
                                      #20

                                      @SPlatten said in QTcpSocket connecting even tho no server?:

                                      as I said previously the IP is just part of the address, the port completes the address, when you establish the connection the port is optional, but if supplied then it should be used because connecting to address and address:port are very different.

                                      Your are mixing up definitions:

                                      • Hostname is IP address or a name (like "www.qt.com")
                                      • portnum is the TCP port (number between 0 and 65534).
                                      • combination of hostname and TCP port is an Endpoint
                                      • a TCP connection is defined as a combination of 2 endpoints, the local endpoint and the remote endpoint

                                      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                                      1 Reply Last reply
                                      9
                                      • D Offline
                                        D Offline
                                        Darta
                                        wrote on last edited by Darta
                                        #21

                                        I have the same issue no listening server at the adress port but it's connecting anyway:

                                        bool Client::bindTo(QString adress, quint16 port)
                                        {
                                            QHostAddress adressToCo;
                                            if (adressToCo.setAddress(adress) == true)
                                            {
                                                m_socket = new QTcpSocket;
                                                if (!m_socket->bind(adressToCo, port)) {
                                                    m_errorMsg = "Cannot connect to " + adress;
                                                    qDebug() << "Cannot connect to " + adress;
                                                }
                                            }
                                            else {
                                                m_errorMsg = "Wrong IP address.";
                                                qDebug() << "Wrong IP address: " + adress;
                                                return false;
                                            }
                                            qDebug() << "Bind corectly to " + adress;
                                            return true;
                                        }
                                        
                                        bool Client::connectTo(QString adress, quint16 port)
                                        {
                                            QHostAddress adressToCo;
                                            adressToCo.setAddress(adress);
                                            QObject::connect(m_socket, &QTcpSocket::readyRead, [=] {
                                                QString msg = m_socket->readAll();
                                                emit msgRcvd(msg);
                                            });
                                            m_socket->connectToHost(adressToCo, port);
                                            if (!m_socket->waitForConnected(5000)) {
                                                m_errorMsg = m_socket->errorString();
                                                qDebug() << "Error socket:" << m_socket->errorString();
                                                return false;
                                            }
                                            else if(m_socket->state() != QAbstractSocket::ConnectedState) {
                                                m_errorMsg = m_socket->errorString();
                                                qDebug() << "Error socket:" << m_socket->errorString();
                                                return false;
                                            }
                                            qDebug() << "Connect corectly to " + adress;
                                            m_socket->write("I'm writing a message that will be lost somewhere over the rainbow");
                                            return true;
                                        }
                                        

                                        I gave the same adress port to both functions :
                                        Adress: "192.168.1.42" Port: 58513

                                        Regardless the port number I put in,
                                        I also could set the adress to "127.0.0.1" it is always the same issue:
                                        the client is connected.

                                        Output of software:

                                        Adress: "192.168.1.42" Port: 58513
                                        "Bind corectly to 192.168.1.42"
                                        "Connect corectly to 192.168.1.42"
                                        Client connected: true
                                        

                                        to get the final line i'm using :

                                            m_socket->state() == QAbstractSocket::ConnectedState ? true : false;
                                        

                                        So everytimes the QTcpSocket connect itself to my adress regardless of my port...
                                        When I launch my server, the server doesn't have any connection either

                                        JonBJ 1 Reply Last reply
                                        0
                                        • D Darta

                                          I have the same issue no listening server at the adress port but it's connecting anyway:

                                          bool Client::bindTo(QString adress, quint16 port)
                                          {
                                              QHostAddress adressToCo;
                                              if (adressToCo.setAddress(adress) == true)
                                              {
                                                  m_socket = new QTcpSocket;
                                                  if (!m_socket->bind(adressToCo, port)) {
                                                      m_errorMsg = "Cannot connect to " + adress;
                                                      qDebug() << "Cannot connect to " + adress;
                                                  }
                                              }
                                              else {
                                                  m_errorMsg = "Wrong IP address.";
                                                  qDebug() << "Wrong IP address: " + adress;
                                                  return false;
                                              }
                                              qDebug() << "Bind corectly to " + adress;
                                              return true;
                                          }
                                          
                                          bool Client::connectTo(QString adress, quint16 port)
                                          {
                                              QHostAddress adressToCo;
                                              adressToCo.setAddress(adress);
                                              QObject::connect(m_socket, &QTcpSocket::readyRead, [=] {
                                                  QString msg = m_socket->readAll();
                                                  emit msgRcvd(msg);
                                              });
                                              m_socket->connectToHost(adressToCo, port);
                                              if (!m_socket->waitForConnected(5000)) {
                                                  m_errorMsg = m_socket->errorString();
                                                  qDebug() << "Error socket:" << m_socket->errorString();
                                                  return false;
                                              }
                                              else if(m_socket->state() != QAbstractSocket::ConnectedState) {
                                                  m_errorMsg = m_socket->errorString();
                                                  qDebug() << "Error socket:" << m_socket->errorString();
                                                  return false;
                                              }
                                              qDebug() << "Connect corectly to " + adress;
                                              m_socket->write("I'm writing a message that will be lost somewhere over the rainbow");
                                              return true;
                                          }
                                          

                                          I gave the same adress port to both functions :
                                          Adress: "192.168.1.42" Port: 58513

                                          Regardless the port number I put in,
                                          I also could set the adress to "127.0.0.1" it is always the same issue:
                                          the client is connected.

                                          Output of software:

                                          Adress: "192.168.1.42" Port: 58513
                                          "Bind corectly to 192.168.1.42"
                                          "Connect corectly to 192.168.1.42"
                                          Client connected: true
                                          

                                          to get the final line i'm using :

                                              m_socket->state() == QAbstractSocket::ConnectedState ? true : false;
                                          

                                          So everytimes the QTcpSocket connect itself to my adress regardless of my port...
                                          When I launch my server, the server doesn't have any connection either

                                          JonBJ Offline
                                          JonBJ Offline
                                          JonB
                                          wrote on last edited by JonB
                                          #22

                                          @Darta said in QTcpSocket connecting even tho no server?:

                                          I have the same issue no listening server at the adress port but it's connecting anyway:

                                          "Bind corectly to 192.168.1.42"

                                          "Connect corectly to 192.168.1.42"

                                          I don't understand. Your bindTo() does the listening, the connectTo() connects to that, they are both using the same port number, your program is acting as both client and server. That's how it looks to me, so what's the problem?

                                          D 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