/*
 * DailyAdviceClient.java
 *
 * Created on August 26, 2003, 8:56 PM
 */

/**
 *
 * @author  do008548
 */

import java.net.*;
import java.io.*;

public class DailyAdviceClient {
    
    /** Holds value of property direccion. */
    private String direccion;
    
    /** Holds value of property puerto. */
    private int puerto;
    
    /** Creates a new instance of DailyAdviceClient */
    public DailyAdviceClient() {
    }
    
    /** Getter for property direccion.
     * @return Value of property direccion.
     */
    public String getDireccion() {
        return this.direccion;
    }
    
    /** Setter for property direccion.
     * @param direccion New value of property direccion.
     */
    public void setDireccion(String direccion) {
        this.direccion = direccion;
    }
    
    /** Getter for property puerto.
     * @return Value of property puerto.
     */
    public int getPuerto() {
        return this.puerto;
    }
    
    /** Setter for property puerto.
     * @param puerto New value of property puerto.
     */
    public void setPuerto(int puerto) {
        this.puerto = puerto;
    }
    
    private Socket s= null;
    
    /** Holds value of property vista. */
    private IVista vista;
    
    public void conectar() {
        try 
        {
            s= new Socket(this.getDireccion(),this.getPuerto());
        } catch (Exception ex){
            ex.printStackTrace();
        }
    }
    
    public void desconectar() {
          try 
        {
            s.close();
        } catch (Exception ex){
            ex.printStackTrace();
        } 
    }
    public void pedirConsejo()
    {
      try
      {
       if (s!=null){
             InputStreamReader entrada =
               new InputStreamReader(s.getInputStream()); 
             BufferedReader lector = new BufferedReader(entrada);
             
             String mensaje = lector.readLine();
             lector.close();
             if (this.getVista() !=null)
                 this.getVista().mostrar(mensaje);
       }    
      } catch (Exception ex){
            ex.printStackTrace();
       }    
    }    
    
    /** Getter for property vista.
     * @return Value of property vista.
     */
    public IVista getVista() {
        return this.vista;
    }
    
    /** Setter for property vista.
     * @param vista New value of property vista.
     */
    public void setVista(IVista vista) {
        this.vista = vista;
    }
    
}
