According to following article, I can create a simple socket in Java to check the availability of a service. However, a port number is needed to check the service.
Check service availability from java
However, if I only have the service name defined in /etc/services, how can I check the service availability? Do I have to get the port number by service name at first? Reference to the following question:
I am expecting some more native way to make OS to translate the service name for me rather than translate it by myself in Java. Thanks.
If you really don’t want to parse
/etc/servicesI fear you’re looking at some JNI or JNA implementation of getservbyname().I would perhaps start by parsing the services file, and look at the native implementation if this isn’t really good enough. Abstract/wrap it so swapping one solution for another isn’t so painful.