Question: In Assignment #2 you did not follow the instructions. Instead of directly reading the /etc/services file you used the standard C functions getportybyname and getportbynum.
In Assignment #2 you did not follow the instructions. Instead of directly reading the /etc/services file you used the standard C functions getportybyname and getportbynum. You also did not attempt the similar exercise on the final to retrieve values from /etc/hosts. (8 marks) Redo this exercise in Java. a) Write and test a method int getportnum(portName) based on the sample program that reads the /etc/services file one line at a time, tokenizes each line, checks both the default name and the aliases and returns the associated port #. If the port does not exist it should throw an exception. (3) b) Write and test a Java method String[] getportname(portNo) that reads the /etc/services file one line at a time, tokenizes each line and returns a list of all unique names for the port. The aliases for the services may be on the same line or on following lines and you may assume that the port numbering is in order. To guarantee uniqueness I suggest using a Hashset to collect the names and at the end of your method convert it to an array. (3) c) Write a small command server that accepts 2 commands to test a. & b: (2) i) service name #display the port # associated with the name ii) port portNo #Displays the list of names associated with the port iii) The command server should handle any exceptions by displaying a message and continuing. iv) Show testing for 3 service names including one that does not exist. v) Show testing for 3 ports #s, one of which should have at least 3 alternative names and one that does not exist.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
