check port in use
-
Hi,
AFAIK, one simple way is to try to connect to that port but you can have a race condition as between the moment you check and the moment you continue your logic, another process may have requested said port.
What is your use case ?
-
@s002wjh Just try to listen on it. If you can listen on it, then it wasn't already in use. If you can't listen on it, it might already be in use.
-
@s002wjh Just try to listen on it. If you can listen on it, then it wasn't already in use. If you can't listen on it, it might already be in use.
@wrosecrans thx, is there example or syntax on listen the port? using http qtwebapp, I have a browser that use local port for the server, and want to make sure there is no conflict with local host port.
-
@wrosecrans thx, is there example or syntax on listen the port? using http qtwebapp, I have a browser that use local port for the server, and want to make sure there is no conflict with local host port.
-
@s002wjh said in check port in use:
is there example or syntax on listen the port
-
can I do this without creating new tcpserver etc?
int test;
test=QTcpServer::listen(QHostAddress::Any, 1234);so if there is something using port 1234 it return 0 or false?
@s002wjh said in check port in use:
can I do this without creating new tcpserver etc?
No, because listen() is not static