import java.net.*; import java.util.*; /** * @author Nicklas Hjalmarsson * @author Torbjörn Nilsson * @version 1.1 * * Class to startup the game */ public class StartupServer{ //Starta med antal spelare som arg /** * Called with argumemt number of players * java StartupServer 2 */ public static void main(String[] args ) { Vector threads = new Vector(2); int PORT = 8282; try { Timeout t = new Timeout(120); // timeout after 2 minutes! t.start(); Fod game = new Fod(); boolean con = false; ServerSocket s = null; while(!con){ try{ s = new ServerSocket(PORT); con = true; }catch (SocketException e) { con = false; PORT++; System.out.println("Connection denied trying new port: "+PORT); } } if(s != null){ for (int i = 1;i<(1+Integer.parseInt(args[0]));i++){ Socket incoming = s.accept(); System.out.println("Spawning " + i); ServerThread ST = new ServerThread(incoming, i,game); ST.start(); threads.addElement(ST); Thread.sleep(500); } t.stop(); game.init(threads); game.start(); } } catch (Exception e) { System.out.println("startupserver: "+e); } } }