示例#1
0
文件: Paket.java 项目: toka88/sedmica
  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
文件: Paket.java 项目: toka88/sedmica
  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
文件: Paket.java 项目: toka88/sedmica
  /**
   * 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;
  }