//
// Client-serveur sur Internet - Classe CONNEXION
//
// <http://cui.unige.ch/java/exemples>
//


import java.io.*;
import java.net.*;

class Connexion extends Thread
{
  protected Socket client;
  protected BufferedReader in;
  protected PrintStream out;

  public Connexion(Socket client_soc)
  {
    client=client_soc;
    try {
      in =new BufferedReader(new InputStreamReader(client.getInputStream()));
      out =new PrintStream(client.getOutputStream());
    } catch (IOException e) {
      try {
        client.close();
      } catch (IOException e1) {
      };
      System.err.println( "Connexion> " + e.getMessage());
      return;
    }
    this.start();
  } // Connexion

	public void run()
	{
		String ligne;
		try {

			while(true) {
				ligne=in.readLine();
				if (ligne.toUpperCase().compareTo("FIN")==0) break; 
				System.out.println( "mesage = " + ligne );
				out.println( ligne.toUpperCase() );
			}
		} catch (IOException e) {
			System.out.println("Connexion>run> " + e.toString());
		} finally {
			try {
				client.close();
			} catch (IOException e) {
			};
		}
	} // run
  
} // class Connexion
