Example #1
0
 /**
  * Slouzi ke zprostredkovani prijmu zpravy ze soketu
  *
  * @param msg zprava
  */
 private synchronized void setMsg(String msg) {
   try {
     if (this.msg != null) {
       wait();
     }
     this.msg = msg;
   } catch (InterruptedException ex) {
     JOptionPane op = new JOptionPane();
     JOptionPane.showMessageDialog(op, ex);
     Game.zastav();
   }
 }
Example #2
0
 /**
  * Connection reprezentuje jednu pripojku k serveru
  *
  * @param client soket klienta
  * @param pocetHracu celkovy pocet hracu
  * @param pocetHracuPoSiti pocet hracu po siti (z pohledu serveru)
  */
 public Connection(Socket client, int pocetHracu, int pocetHracuPoSiti) {
   try {
     this.client = client;
     out = new PrintWriter(client.getOutputStream());
     in = new BufferedReader(new InputStreamReader(client.getInputStream()));
     send("hraci:" + pocetHracu + ":" + pocetHracuPoSiti);
     this.start();
   } catch (IOException ex) {
     JOptionPane op = new JOptionPane();
     JOptionPane.showMessageDialog(op, ex);
     Game.zastav();
   }
 }
Example #3
0
 @Override
 public void run() {
   try {
     String line;
     while ((line = in.readLine()) != null) {
       setMsg(line);
     }
   } catch (IOException ex) {
     JOptionPane op = new JOptionPane();
     JOptionPane.showMessageDialog(op, ex);
     Game.zastav();
   } finally {
     try {
       out.close();
       in.close();
       client.close();
     } catch (IOException ex) {
       JOptionPane op = new JOptionPane();
       JOptionPane.showMessageDialog(op, ex);
       Game.zastav();
     }
   }
 }