Is there a platform independent way in Qt to get an unused TCP port? I have a need to launch an existing application which must be given an open TCP port in order for it to work.
Enter "telnet + IP address or hostname + port number" (e.g., telnet www.example.com 1723 or telnet 10.17. xxx. xxx 5000) to run the telnet command in Command Prompt and test the TCP port status. If the port is open, only a cursor will show.
You can use netstat command to list the tcp port, if 443 port is listed there and state is established means 443 is open for outbound communication.
Use ss command to display all open TCP and UDP ports in Linux. Another option is to use the netstat command to list all ports in Linux. Apart from ss / netstat one can use the lsof command to list open files and ports on Linux based system. Finally, one can use nmap command to check TCP and UDP ports too.
use QTcpServer is easier way.
bool QTcpServer::listen(const QHostAddress & address = QHostAddress::Any, quint16 port = 0)
If port
is 0, a port
is chosen automatically, then you use quint16 QTcpServer::serverPort() const
to get the "idle" port
then close your Tcp Server
OR
generate a ramdom port, use QTcpSocket
to connect it(local connection)
QTcpSocket::localPort()
and close this tcp socketIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With