John_Woo said:
Hi,
if there are several java app (other app) in a machine occupying some
ports, and a few of them are java app using ports for Socket Server
(those app pickup randomly a port from a fixed range).
I'm wondering, how to know which port is used by my java app?
Normally, when you create a user port, the OS picks it, and it chooses
one that is not in use, so you are good.
If you require a specific port, that should be configured by your
Administrator, and read in by your app as part of it's configuration.
It's the administrator's responsibility to make sure two apps aren't
configured on the same port.
For example, on my FreeBSD system, ports are configured in
/etc/services, and to a lesser extant /etc/protocols. Even the echo
protocol, which everyone knows runs on port 7, is still configured in
/etc/services, so I could change it to any port if I really wanted too.
You need to decide how and who you want to configure your ports, then
read the ports out of that configuration repository. Allow for command
line and local config too, just for convenience. Most Java apps have
some sort of XML file in their .jar for configuration, but don't
overlook the convenience of having all network config in one spot like
/etc/services.
If you are just testing, just choose one you know you aren't using.