Click to See Complete Forum and Search --> : Best to know whether a port is being used by some other app...


KaramChand03
January 11th, 2005, 12:36 AM
What is the best way to know whether a port is being used by some other app in a host?

My app needs to create and listen on a port so I just wanted to make sure that the port is not being used (lisetend) by some other process.

cilu
January 11th, 2005, 03:24 AM
One of the error codes returned by bind is WSAEADDRINUSE.

Address already in use.
Typically, only one usage of each socket address (protocol/IP address/port) is permitted. This error occurs if an application attempts to bind a socket to an IP address/port that has already been used for an existing socket, or a socket that was not closed properly, or one that is still in the process of closing. For server applications that need to bind multiple sockets to the same port number, consider using setsockopt (SO_REUSEADDR). Client applications usually need not call bind at all—connect chooses an unused port automatically. When bind is called with a wildcard address (involving ADDR_ANY), a WSAEADDRINUSE error could be delayed until the specific address is committed. This could happen with a call to another function later, including connect, listen, WSAConnect, or WSAJoinLeaf.

KaramChand03
January 11th, 2005, 04:58 AM
Thx.

That should work :)

Andreas Masur
January 11th, 2005, 06:42 AM
[ Moved thread ]