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 Updated to NodeBB v4.3 + New Features

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 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)

    jsulmJ 1 Reply Last reply
    0
    • W w.tkm

      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)

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on 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
      0
      • jsulmJ jsulm

        @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 last edited by
        #3

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

        jsulmJ 1 Reply Last reply
        0
        • W w.tkm

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

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on 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
          0
          • jsulmJ jsulm

            @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 last edited by
            #5

            @jsulm
            No, fnTcpConnect is called constructor.

            jsulmJ 1 Reply Last reply
            0
            • W w.tkm

              @jsulm
              No, fnTcpConnect is called constructor.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on 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
              2
              • jsulmJ jsulm

                @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 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

                • Login

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