QTcpClient successfully connects, but not to my server. Where is it connecting?

后端 未结 3 1527
小鲜肉
小鲜肉 2021-02-10 14:36

I have successfully built a thin client/server using Qt\'s Tcp Sockets API. I know it works very well, because I have sent plenty of data over the wire and verified it. Howeve

相关标签:
3条回答
  • 2021-02-10 15:20

    Verify the return value of qDummyServer->listen(). It should return true if the server is indeed listening at port 9000. If it returns false, chances are port 9000 is blocked by another process, and it couldn't listen. In that case, your qTestSocket connected to that other process instead of your own server.

    0 讨论(0)
  • 2021-02-10 15:23

    While QTEST_MAIN creates a QApplication and runs all your tests, it does so sequentially and not with an event loop. Therefore, while your socket can indeed connect to the server (meaning qTestSocket->waitForConnected() returns true), since the app doesn't return to an event loop, the QTcpServer's signal will not get emitted, and TcpCommSocketTest::connectDummyServer() never gets called.

    Try adding a call to qApp->processEvents() at the end of initTestCase(). It should let connectDummyServer() be called.

    0 讨论(0)
  • 2021-02-10 15:29

    You could be connecting to an instance of the server started earlier. Poke around with a process monitor to make sure you don't have any stray instances. Does your test setup automatically kick off and shutdown the dummy server? It could be that the test is succesfully starting the server, but failing to kill it.

    Also, from the 127.0.0.1, the dummy server is running on the same machine as the test code right?

    0 讨论(0)
提交回复
热议问题