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. Unexplained infinite loop during TCP connection.
Forum Update on Monday, May 27th 2025

Unexplained infinite loop during TCP connection.

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 471 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.
  • W Offline
    W Offline
    w.tkm
    wrote on 25 Aug 2022, 02:15 last edited by
    #1

    I want to do TCP communication. but, Unexplained infinite loop during TCP connection.
    I don't have it specifically set to loop.

    An infinite loop occurs between A and B in the code below
    If the IP of the [connectToHost] is used as the loopback address, this problem does not occur.
    Is it a code problem or a PC configuration problem?

    QTcpSocket  *m_pTcpSocket;
    
    void MyTcp::fnTcpConnect(QString sTcpConnectHostIP, quint16 uiTcpConnectPort, QString sTcpClientIP)
    {
    //A
    	connect(m_pTcpSocket, SIGNAL(readyRead()), this, SLOT(fnTcpRecvWifiData()));
    	connect(m_pTcpSocket, &QAbstractSocket::stateChanged, this, &CcuTcp::fnTcpWifiStateChanged );
    
    	m_pTcpSocket->setProxy(QNetworkProxy::NoProxy);
    	m_pTcpSocket->bind( QHostAddress( sTcpClientIP ), QAbstractSocket::DefaultForPlatform);
    
    //B
    	m_pTcpSocket->connectToHost( sTcpConnectHostIP, uiTcpConnectPort );
    
    }
    

    <Environment>
    Qt: 5.15.2 MinGW 64bit
    OS: Windows10(Virtual machine on Linux)

    J 1 Reply Last reply 25 Aug 2022, 05:21
    0
    • W w.tkm
      25 Aug 2022, 02:15

      I want to do TCP communication. but, Unexplained infinite loop during TCP connection.
      I don't have it specifically set to loop.

      An infinite loop occurs between A and B in the code below
      If the IP of the [connectToHost] is used as the loopback address, this problem does not occur.
      Is it a code problem or a PC configuration problem?

      QTcpSocket  *m_pTcpSocket;
      
      void MyTcp::fnTcpConnect(QString sTcpConnectHostIP, quint16 uiTcpConnectPort, QString sTcpClientIP)
      {
      //A
      	connect(m_pTcpSocket, SIGNAL(readyRead()), this, SLOT(fnTcpRecvWifiData()));
      	connect(m_pTcpSocket, &QAbstractSocket::stateChanged, this, &CcuTcp::fnTcpWifiStateChanged );
      
      	m_pTcpSocket->setProxy(QNetworkProxy::NoProxy);
      	m_pTcpSocket->bind( QHostAddress( sTcpClientIP ), QAbstractSocket::DefaultForPlatform);
      
      //B
      	m_pTcpSocket->connectToHost( sTcpConnectHostIP, uiTcpConnectPort );
      
      }
      

      <Environment>
      Qt: 5.15.2 MinGW 64bit
      OS: Windows10(Virtual machine on Linux)

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 25 Aug 2022, 05:21 last edited by
      #2

      @w-tkm said in Unexplained infinite loop during TCP connection.:

      An infinite loop occurs between A and B in the code below

      What exactly do you mean by "infinite loop"? What is looping?

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

      W 1 Reply Last reply 25 Aug 2022, 05:40
      0
      • J jsulm
        25 Aug 2022, 05:21

        @w-tkm said in Unexplained infinite loop during TCP connection.:

        An infinite loop occurs between A and B in the code below

        What exactly do you mean by "infinite loop"? What is looping?

        W Offline
        W Offline
        w.tkm
        wrote on 25 Aug 2022, 05:40 last edited by
        #3

        @jsulm
        The code is executed again from position A.
        Then, when executed to position B, repeat back to A.

        J 1 Reply Last reply 25 Aug 2022, 05:43
        0
        • W w.tkm
          25 Aug 2022, 05:40

          @jsulm
          The code is executed again from position A.
          Then, when executed to position B, repeat back to A.

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 25 Aug 2022, 05:43 last edited by
          #4

          @w-tkm That means that fnTcpConnect is called again: is fnTcpConnect a slot connected to a signal? If so - what signal is it connected to?

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

          W 1 Reply Last reply 25 Aug 2022, 05:45
          0
          • J jsulm
            25 Aug 2022, 05:43

            @w-tkm That means that fnTcpConnect is called again: is fnTcpConnect a slot connected to a signal? If so - what signal is it connected to?

            W Offline
            W Offline
            w.tkm
            wrote on 25 Aug 2022, 05:45 last edited by
            #5

            @jsulm
            No, fnTcpConnect is called constructor.

            J 1 Reply Last reply 25 Aug 2022, 05:50
            0
            • W w.tkm
              25 Aug 2022, 05:45

              @jsulm
              No, fnTcpConnect is called constructor.

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 25 Aug 2022, 05:50 last edited by jsulm
              #6

              @w-tkm Then I have no idea how it is possible that it is called again and again. Please make sure it is really not connected to any slots and that you are not creating MyTcp instance again and again. Use debugger...

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

              W 1 Reply Last reply 25 Aug 2022, 07:30
              2
              • J jsulm
                25 Aug 2022, 05:50

                @w-tkm Then I have no idea how it is possible that it is called again and again. Please make sure it is really not connected to any slots and that you are not creating MyTcp instance again and again. Use debugger...

                W Offline
                W Offline
                w.tkm
                wrote on 25 Aug 2022, 07:30 last edited by
                #7

                @jsulm
                If the IP address of connectToHost is set to 127.0.0.1, it will not be called after that.
                Also, if I add a subnet with the desired IP address to the virtual NIC, it will not be called again.
                (If I want to connect to 192.168.50.1, add 192.168.50.0)

                Apparently there was a problem with the operation in the virtual environment.
                I've never been able to figure out what caused it, but...

                1 Reply Last reply
                0

                1/7

                25 Aug 2022, 02:15

                • Login

                • Login or register to search.
                1 out of 7
                • First post
                  1/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved