Well this is a little feature i have added to my server. It enables you to change the port on startup. It also gives you an option to remeber the port. It all saves to an ini file.
Code:
Properties parser = new Properties();
parser.load(new FileInputStream("data/settings.ini"));
int port = 0;
if (Boolean.parseBoolean(parser.getProperty("portRem")) == false) {
String portString = JOptionPane.showInputDialog(null,"Please enter the port which you would like the server to listen on:");
String remeber = JOptionPane.showInputDialog(null,"Do you want this port to be remembered?");
port = Integer.parseInt(portString);
if (remeber.equals("yes")) {
parser.setProperty("portRem", "true");
parser.setProperty("port", portString);
FileOutputStream out = new FileOutputStream("data/settings.ini");
parser.store(out, "");
}
} else {
port = Integer.parseInt(parser.getProperty("port"));
}
Add this before all the other code in the Main method. You may need to add a few imports to the top of your class file. You need to create a new file will the extention .ini and paste this into it
Code:
port=43594
portRem=false
The server will save the port into it.
You may get some errors about exceptions not being thrown... Just make the main method throw Exception....
Code:
public static void main(String args[]) throws Exception {