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

class Servidor
{
	public static void main(String argv[]) throws Exception
 	{
		String clientSentence;
      String capitalizedSentence;
	  	boolean idok;
	  	String close = "close";
      ServerSocket welcomeSocket = new ServerSocket(6789);
      Vector pacientes = new Vector();
      String total;
      Vector treads_calculadoras=new Vector(0);
      Socket connectionSocket;
		for (;;)
     	{
			idok=false;
			connectionSocket = welcomeSocket.accept();
			BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
	      DataOutputStream  outToClient =new DataOutputStream(connectionSocket.getOutputStream());
			clientSentence = inFromClient.readLine();
			if(clientSentence.compareTo("cliente")==0)
			{
				System.out.println("\nNuevo cliente Conectado");
				Thread t = new conexion(connectionSocket,treads_calculadoras);
				t.start();
				idok=true;
			}
			if(clientSentence.compareTo("calculadora")==0)
			{
				System.out.println("\nNueva calculadora conectada ");
				conexioncalc calc= new conexioncalc(connectionSocket);
				treads_calculadoras.add(calc);
				idok=true;
			}
			if(!idok)
			{
				connectionSocket.close();
			}
	            //Thread t = new ThreadedEchoHandler(connectionSocket);
		}
	}
}
