is someone know here how it possible to know if a port is in use or not
imagine you have your serveur who want toopen multiple listener socket
exple
while(kljfdlkljkdf)
if this port is ok listenat this port
else
port++
Printable View
is someone know here how it possible to know if a port is in use or not
imagine you have your serveur who want toopen multiple listener socket
exple
while(kljfdlkljkdf)
if this port is ok listenat this port
else
port++
You could try to open each port, on ports already in use the listen function should return an error code.
Other way would be to manually attempt connections to 127.0.0.1 (localhost) at port X, if you are able to connect to it then it is listening, close the connection and proceed to the next port.
I believe the IP Helper API has functions that can help you here. In particular, GetTcpTable can enumerate open TCP ports on the various addresses mapped by the machine, and there is a similar UDP function. Additionally, full source code is available here for a program that shows how to use the IP Helper API to get all sorts of useful information. I hope this is helpful!
thx for the tow solutions
but i think i prefer try a listning in this case.
there is a socket error
it's not too long to execute