Im using this code:
final int LOCK_PORT= 54321;
ServerSocket ss = new ServerSocket(LOCK_PORT);
The thing is that in the same port you cannot listen to 2 different applications (teachers theory).
This code was implemented into an application and the same instance ran more than 1 time. The objective is that the same instance is not suposed to run more than 1 time in the same port. However this isnt working and it does run...
// Edited, more code...
public VentanaPropiedades() {
initFirst();
initComponents(); //graphic components of Matisse
}
private void initFirst() {
loadProperties(); //just internal values of the program, nothing to do
activateInstance();
}
private void activateInstance() throws Exception {
try {
final int LOCK_PORT= 54321;
ServerSocket ss = new ServerSocket(LOCK_PORT);
} catch (Exception e) {
System.out.println(e);
throw e;
}
}
private void killProgram() {
setVisible(false);
dispose();
System.exit(0);
}
private void validateInstance() {
try {
activateInstance();
} catch (Exception ex) {
killProgram();
}
}
--------------------------Supposed Solution---------------------------
The error catched when the 2nd instance DOES NOT RUN is this one:
java.net.BindException: Address already in use: JVM_Bind
However, this error not always happens and you can run more than 1 instance of the same program.