예제 #1
0
파일: Server.java 프로젝트: ThierryL/PacMan
 public void disconnect(String name, I_InfoPlayer player) {
   try {
     Naming.unbind("rmi://" + serverInfo.getIpAddr() + ":1099/I_InfoGame");
     Naming.unbind("rmi://" + serverInfo.getIpAddr() + ":1099/" + name);
   } catch (Exception e) {
     System.out.println("Failed unbind");
     System.exit(128);
   }
   System.out.println("Disconnected");
   ServerTimer timer = new ServerTimer(5);
   Thread thread = new Thread(timer);
   thread.start();
   while (!timer.finished()) ;
   timer.shutDown();
   timer = null;
   System.gc();
   try {
     Naming.rebind("rmi://" + serverAddress + ":1099/I_InfoGame", game);
     Naming.rebind("rmi://" + serverAddress + ":1099/" + name, player);
   } catch (Exception e) {
     System.out.println("Failed rebind");
     System.exit(128);
   }
   System.out.println("Reconnected");
 }
예제 #2
0
파일: Server.java 프로젝트: ThierryL/PacMan
 public static void serverInit() {
   String serverAddress = "rmi://" + serverInfo.getIpAddr() + ":1099/I_InfoGame";
   try {
     game = new InfoGame();
     server = new Server();
     game.setServer(server);
     game.setServerAddress(serverInfo.getIpAddr());
     game.setNextAddress(serverInfo.getNext().getIpAddr());
     game.setNbPlayerExpected(numPlayer);
     Naming.rebind(serverAddress, game);
     socketPortClient = serverInfo.getPortClient();
     // System.out.println("End initialisation");
   } catch (RemoteException e) {
     System.out.println("Hubo una excepcion creando la instancia del objeto distribuido");
   } catch (MalformedURLException e) {
     System.out.println("URL mal formada al tratar de publicar el objeto");
   }
 }
예제 #3
0
파일: Server.java 프로젝트: ThierryL/PacMan
  private static void serverCall() throws Exception {
    String sentence = "move";
    String line;

    while (!gameStopped) {
      System.out.print("");
    }
    playing = false;
    try {
      setDiscussion();
    } catch (Exception ex) {
      System.out.println("Failed to discuss with clients");
    }

    BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
    try {
      InetAddress inetAddress = InetAddress.getByName(serverInfo.getNext().getIpAddr());
      Socket clientSocket = new Socket(inetAddress, serverInfo.getNext().getPort());
      DataOutputStream out = new DataOutputStream(clientSocket.getOutputStream());
      BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
      sendInfo(out);
      line = in.readLine();
      while (!game.getUnbinding()) ;
      Naming.unbind("rmi://" + serverInfo.getIpAddr() + ":1099/I_InfoGame");
      out.writeBytes("Unbinding finished\n");
      line = in.readLine();
      clientSocket.close();
    } catch (RemoteException e) {
      System.out.println("Failed get info from game");
      System.exit(1);
    } catch (Exception ex) {
      System.out.println("Failed to socket with waiting server");
    }
    discussion.shutDown();
    discussion = null;
    game = null;
    System.gc();
    serverWaiting();
  }