diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/server/MdgaServer.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/server/MdgaServer.java index 8823b65e..f1780baf 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/server/MdgaServer.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/server/MdgaServer.java @@ -26,6 +26,7 @@ public class MdgaServer implements MessageListener, Connection private static final Logger LOGGER = System.getLogger(MdgaServer.class.getName()); private Server myServer; + private static int port; private final ServerGameLogic logic; private final BlockingQueue pendingMessages = new LinkedBlockingQueue<>(); @@ -41,37 +42,38 @@ public class MdgaServer implements MessageListener, Connection } /** - * Starts the Battleships server. + * Constructor. + * + * @param port as the port for this server */ - public static void main(String[] args) { - new MdgaServer().run(); - } - - /** - * Creates a new MdgaServer. - */ - public MdgaServer() { + public MdgaServer(int port) { + MdgaServer.port = port; LOGGER.log(Level.INFO, "Creating MdgaServer"); //NON-NLS logic = new ServerGameLogic(this, new Game()); } + /** + * + */ public void run() { startServer(); - this.connectionAdded(myServer, myServer.getConnection(0)); while (true) processNextMessage(); } + /** + * + */ private void startServer() { try { LOGGER.log(Level.INFO, "Starting server..."); //NON-NLS - myServer = Network.createServer(1234); - + myServer = Network.createServer(port); initializeSerializables(); myServer.start(); registerListeners(); LOGGER.log(Level.INFO, "Server started: {0}", myServer.isRunning()); //NON-NLS - } catch (IOException e) { + } + catch (IOException e) { LOGGER.log(Level.ERROR, "Couldn't start server: {0}", e.getMessage()); //NON-NLS exit(1); } @@ -186,8 +188,6 @@ private void messageReceived(HostedConnection source, ClientMessage message) { @Override public void connectionAdded(Server server, HostedConnection hostedConnection) { LOGGER.log(Level.INFO, "new connection {0}", hostedConnection); //NON-NLS - // ToDo: Synchronize data between server and client. - logic.getGame().addPlayer(hostedConnection.getId(), new Player()); } @Override