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
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.
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.
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?