TcpSocket stateChanged signal is not emit
-
Hi.
I use Tcp in an application. (No special features.)
That application is the client, and another application is the server.I ran the application before running the server application.
Then client application's socket was not emit [stateChanged].
However, It was able to connect to the server and send/receive data.If the server is up and running, [stateChanged] is emit.
Why is this? -
@w-tkm I don't understand: if the server is not running how can your client connect and send/receive data?!
Also, what daes this mean: "I ran the application before running the server application.( after running the server application )"? Do you start client before or after server? Please explain clearly.
-
void CcuTcp::fnTcpClientSet(QString sTcpConnectIP, quint16 uiTcpConnectPort, QString sTcpBindIP) { connect(m_pTcpSocket, SIGNAL(readyRead()), this, SLOT(fnTcpRecvData())); connect(m_pTcpSocket, &QAbstractSocket::stateChanged, this, &CcuTcp::fnTcpStateChanged ); m_pTcpSocket->setProxy(QNetworkProxy::NoProxy); m_pTcpSocket->bind( QHostAddress( sTcpBindIP ), QAbstractSocket::DefaultForPlatform); m_pTcpSocket->connectToHost( sTcpConnectIP, uiTcpConnectPort ); } void CcuTcp::fnTcpStateChanged() { switch ( m_pTcpSocket->state() ) { case QAbstractSocket::UnconnectedState: emit fnSocketState(TCP_STATE_UNCONNECT); break; case QAbstractSocket::ConnectingState: emit fnSocketState(TCP_STATE_CONNECTING); break; case QAbstractSocket::ConnectedState: emit fnSocketState(TCP_STATE_CONNECTED); break; case QAbstractSocket::ClosingState: emit fnSocketState(TCP_STATE_CLOSING); break; default: break; } }
[TCP_STATE_...] is Macro.
-
@w-tkm said in TcpSocket stateChanged signal is not emit:
case QAbstractSocket::UnconnectedState: emit fnSocketState(TCP_STATE_UNCONNECT); break;
case QAbstractSocket::ConnectingState: emit fnSocketState(TCP_STATE_CONNECTING); break;
case QAbstractSocket::ConnectedState: emit fnSocketState(TCP_STATE_CONNECTED); break;
case QAbstractSocket::ClosingState:There are more states which you do not cover