Thread: Port Changer on server startup

Results 1 to 5 of 5
  1. #1 Port Changer on server startup 
    Registered Member
    craig903's Avatar
    Join Date
    Sep 2007
    Age
    30
    Posts
    1,357
    Thanks given
    14
    Thanks received
    92
    Rep Power
    238
    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 {
    Visit Rune Miracle Here
    Reply With Quote  
     

  2. #2  
    Renown Programmer

    Nikki's Avatar
    Join Date
    Aug 2008
    Posts
    3,992
    Thanks given
    553
    Thanks received
    1,078
    Rep Power
    5000
    Hmm, wouldnt this mess with auto restarter? Because it sounds like it asks for port every time at startup
    Please don't add/pm me asking for RSPS help!

    Links:
    - Pastebin
    - Sleeksnap

    Reply With Quote  
     

  3. #3  
    Codex
    Rowan's Avatar
    Join Date
    Sep 2008
    Age
    28
    Posts
    1,593
    Thanks given
    0
    Thanks received
    20
    Rep Power
    1092
    Nice I guess.
    Reply With Quote  
     

  4. #4  
    Donator Port Changer on server startup Market Banned



    Join Date
    Feb 2009
    Posts
    3,820
    Thanks given
    88
    Thanks received
    113
    Rep Power
    5000
    Nice
    Reply With Quote  
     

  5. #5  
    Registered Member
    craig903's Avatar
    Join Date
    Sep 2007
    Age
    30
    Posts
    1,357
    Thanks given
    14
    Thanks received
    92
    Rep Power
    238
    Quote Originally Posted by Nicole View Post
    Hmm, wouldnt this mess with auto restarter? Because it sounds like it asks for port every time at startup
    Yes it would mess with autostarter's. Didn't think of that.

    But if you type yes to remember the port it will save and won't ask you again. So you will only have to set the port once.
    Visit Rune Miracle Here
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •