using QTcpServer is easier.
bool QTcpServer::listen(const QHostAddress & address = QHostAddress::Any, quint16 port = 0)
If port0, a portis automatically selected, then you use quint16 QTcpServer::serverPort() constto get an "unoccupied" port
then close your tcp server
OR
create ramdom port, use QTcpSocketto connect it (local connection)
- ,
QTcpSocket::localPort() tcp - , ;