Getting a port (WinSock)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello, my app sends and receives messages over a local area network using
WinSock, so I need a Port, How can I get an unused port? It must work with
VC6 and Win98/ME too.

Thanks in advance,
William GS
 
AFAIK there is no easy way for getting a free port... in any case, If you
open a port in a 'random' port number, how do you say to the clients which
port the server is using?
And what about firewalls, they usually need to know the port number.
The usual approach is to make the port configurable by the user, and raise
an error if the port is in use.

--
Un saludo
Rodrigo Corral González [MVP]

FAQ de microsoft.public.es.vc++
http://rcorral.mvps.org
 
William said:
Hello, my app sends and receives messages over a local area network
using WinSock, so I need a Port, How can I get an unused port? It
must work with VC6 and Win98/ME too.

If your soft is a client and you want to connect to an existing server, you
just need to call connect (or WSAConnect) : the system will allocate a free
anonymous port to you, and you don't need to worry about it.

Arnaud
MVP - VC
 
Back
Top