import java.io.*;
import java.net.*;
class Cliente 
{
	public static void main(String argv[]) throws Exception
   {
  		int i; 	
		String sentence="cliente";
      String modifiedSentence;
      String close = "close";
      BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
      Socket clientSocket = new Socket("localhost", 6789);
      DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
      BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
		System.out.println("Conexion aceptada \nIngrese sus calculos solo + - / y * y use espacio para separar elementos y/o números , para finalizar escriba  close");
		try 
		{
	   	outToServer.writeBytes(sentence + '\n');
		}
		catch(IOException e) 
		{
			System.out.printf("Error comunicacion con servidor");
			clientSocket.close();
			System.exit(-1);
		}
		while(true)
		{
			i = 0;
			sentence = inFromUser.readLine();
			try 
			{
        		outToServer.writeBytes(sentence + '\n');
			}
			catch(IOException e)
			{
				System.out.printf("Error comunicacion con servidor");
				clientSocket.close();
				System.exit(-1);
			}
        	if(sentence.compareTo(close) == 0)
        	{
				System.out.println(" Conexion cerrada ");
				clientSocket.close();
				break;
			}
			modifiedSentence = inFromServer.readLine();
			System.out.println("FROM SERVER:  La respuesta es :" + modifiedSentence);
		}
	}
}
