Esempio n. 1
0
  private static void serverWaiting() throws Exception {
    System.out.println("Waiting Mode");
    ServerSocket waitingSocket = new ServerSocket(serverInfo.getPort());
    String line;

    while (true) {
      Socket connectionSocket = waitingSocket.accept();
      BufferedReader in =
          new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
      DataOutputStream out = new DataOutputStream(connectionSocket.getOutputStream());
      // System.out.println("Waiting for migration");
      line = in.readLine();
      // System.out.println("Received: " + line);
      String info = line;
      out.writeBytes("Info OK\n");
      line = in.readLine();
      // System.out.println("Received: " + line);
      serverInit();
      game.setMoving(true);
      reconstruction(info);
      out.writeBytes("Bind OK\n");
      waitingSocket.close();
      break;
    }
    while (!allConnected) {
      System.out.print("");
    }
    game.setMoving(false);
    // System.out.println("Fin server waiting");
    serverRunning();
  }
Esempio n. 2
0
 private static void serverRunning() {
   System.out.println("Server Running");
   ServerTimer timer = new ServerTimer(60);
   Thread thread = new Thread(timer);
   thread.start();
   // System.out.println("Waiting for timer");
   while (!timer.finished()) ;
   timer.shutDown();
   // System.out.println("Migration !");
   timer = null;
   System.gc();
   try {
     game.setMoving(true);
     serverCall();
   } catch (RemoteException e) {
     System.out.println("Failed to modify game");
     System.exit(1);
   } catch (Exception ex) {
     System.out.println("Failed to call");
   }
 }