On Tue, 01 Jan 2008 23:58:54 -0800, naamala <ra********@gmail.comwrote:
But I need to get a random unused port number.
How can I get this unused port number Or How can I check whether the
port number is under usage or not?
It would be better if you could explain what the higher-level goal is.
That said, if you don't care what the port is, you should simply not
specify it. Or rather, specify 0 for the port. Winsock (on which the
..NET Socket class is built) will simply pick a port for you in that case.
In most cases, you don't even need to bind the socket explicitly. Just
create your socket and use it (connect for TCP, any send for UDP) and it
will automatically be bound, to an available port.
Pete