Listen on random port

Discussion in 'Spigot Help' started by helmwet, Apr 17, 2017.

  1. I want a spigot server to listen on a random port when it is ran. Is there any way to do this? (Instead of port 25565 or something else, let spigot assign a random port number.)
     
  2. You can write a Java application which is started before the server and adapts the .properties file with a random value. The application can then start the server too.
     
  3. How can I know that the port is not already in use?
     
  4. Good question: D
    Try to create a server on this port. If it fails you use another port.
    Code (Text):
    ServerSocket serverSocket = new ServerSocket(portNumber);