Getting a port (WinSock)

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
 
R

Rodrigo Corral [MVP]

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
 
A

Arnaud Debaene

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top