Review the code below:
|
Code:
|
int PortNumber = 1500;
ServerSocket MyService;
try {
MyServerice = new ServerSocket(PortNumber);
}
catch (IOException e) {
System.out.println(e);
} |
I have hard coded the port. If port is already occupied, exception will be thrown. I want to catch that exception and want my program to retry by adding 1 to it until connection is made. How this can be done?