Пример #1
0
  public String cekajPotez(int idSobe) {
    connect();
    try {
      ObjectOutputStream paketZaServer = new ObjectOutputStream(klijentSocket.getOutputStream());
      NabaviPaket paket = new NabaviPaket(23);
      paket.setIdSobe(idSobe);
      paketZaServer.writeObject(paket);

      ObjectInputStream paketOdServera = new ObjectInputStream(klijentSocket.getInputStream());
      NabaviPaket paketSKljucem = (NabaviPaket) paketOdServera.readObject();

      paketZaServer.close();
      paketOdServera.close();
      System.out.println("CekajPotez -> " + paketSKljucem.getErr());
      return paketSKljucem.getErr();
    } catch (IOException ioe) {
      System.out.println("Iznimka ulaza/izlaza");
      System.exit(1);
    } catch (ClassNotFoundException k) {
      System.out.println("Dobivena kriva klasa " + k);
    } finally {
      close();
    }
    return null;
  }
Пример #2
0
  public LjudiUSobi dohvatiLjudeUSobi(int idSobe, int kljucKorisnika) {
    connect();
    try {
      ObjectOutputStream paketZaServer = new ObjectOutputStream(klijentSocket.getOutputStream());
      NabaviPaket paket = new NabaviPaket(16);
      paket.setIdSobe(idSobe);
      paket.setKljuc(kljucKorisnika);
      paketZaServer.writeObject(paket);

      ObjectInputStream paketOdServera = new ObjectInputStream(klijentSocket.getInputStream());
      NabaviPaket paketLjudima = (NabaviPaket) paketOdServera.readObject();

      paketZaServer.close();
      paketOdServera.close();

      LjudiUSobi ljudi = new LjudiUSobi();
      ljudi.setLjudiUSobi(paketLjudima.getUser().split(","));
      ljudi.setMaxLjudi(paketLjudima.getKljuc());
      return ljudi;
    } catch (IOException ioe) {
      System.out.println("Iznimka ulaza/izlaza");
      System.exit(1);
    } catch (ClassNotFoundException k) {
      System.out.println("Dobivena kriva klasa " + k);
    } finally {
      close();
    }
    return null;
  }
Пример #3
0
  /**
   * Pokreæe DretvaPartija na serveru.
   *
   * @param idSobe
   * @return uspjesno pokrenuta dretva.
   */
  public boolean zapocniIgru(int idSobe) {
    connect();
    try {
      ObjectOutputStream paketZaServer = new ObjectOutputStream(klijentSocket.getOutputStream());
      NabaviPaket paket = new NabaviPaket(5);
      paket.setIdSobe(idSobe);
      paketZaServer.writeObject(paket);

      ObjectInputStream paketOdServera = new ObjectInputStream(klijentSocket.getInputStream());
      NabaviPaket paketSKljucem = (NabaviPaket) paketOdServera.readObject();
      if (paketSKljucem.isIndex(5)) {
        return true;
      } else if (paketSKljucem.isIndex(-1)) {
        return false;
      }

      paketZaServer.close();
      paketOdServera.close();
    } catch (IOException ioe) {
      System.out.println("Iznimka ulaza/izlaza");
      System.exit(1);
    } catch (ClassNotFoundException k) {
      System.out.println("Dobivena kriva klasa " + k);
    } finally {
      close();
    }
    return false;
  }