Unexplained infinite loop during TCP connection.
-
wrote on 25 Aug 2022, 02:15 last edited by
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) -
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)@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-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?
-
@jsulm
The code is executed again from position A.
Then, when executed to position B, repeat back to A.@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-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-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-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...
wrote on 25 Aug 2022, 07:30 last edited by@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/7