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

class conexioncalc
{
	String clientSentence;
   String capitalizedSentence;
	String close = "close";
   String total;
   Socket connectionSocket;
   boolean busy = false;
   boolean conectado = true;

	public conexioncalc(Socket connectionSocket) throws Exception
   {
 		this.connectionSocket=connectionSocket;
	  	this.conectado = true;
	}

   public String calculasend(String calculo)
   {
		try
		{
			this.busy = true;
			String capitalizedSentence,clientSentence;
			BufferedReader inFromClient = new BufferedReader(new InputStreamReader(this.connectionSocket.getInputStream()));
        	DataOutputStream  outToClient = new DataOutputStream(this.connectionSocket.getOutputStream());
			capitalizedSentence= ""+calculo+'\n';
			try 
			{
				//System.out.println("enviando ");
				outToClient.writeBytes(capitalizedSentence);
			}
			catch(IOException e)
			{
				System.out.printf("Error comunicacion con el cliente");
				connectionSocket.close();
				conectado=false;
			}
        	if(conectado)
        	{
				//System.out.println("recibiendo ");
        		clientSentence = inFromClient.readLine();
				this.busy = false;
				return clientSentence;
			}
			else
			{
			   clientSentence ="Error";
			   this.busy = false;
			   return clientSentence;
			}
		}
		catch(IOException e)
		{
		}
		//System.out.println("retornando "+ clientSentence +"");
		return clientSentence;
	}
}