package smserve_main;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

import smprot.Chooser;

public class Clienthandle extends Thread {
	private Socket conn;
	public Clienthandle(Socket pSock) {
		this.conn = pSock;
	}
	
	public void run() {
		try {

		System.out.println("Client " + conn.getInetAddress() + " connected!");
		BufferedReader br;
		PrintWriter pw;
		br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
		pw = new PrintWriter(conn.getOutputStream());
		
		pw.println("Hello | SMserve 0.1.0");
		// pw is the nice Phrickle Writer with funny C stack like flush(). 
		// This is a funny function that gives you 80s feeling
		pw.flush();
		try {
			Chooser.choose(br.readLine(), br, pw);
		} catch(Exception ex) { System.out.println("Oh my dear bad client buuuh");}
		pw.println("EOT");
		pw.flush();
		
		conn.close();
		} catch (Exception e) {
			System.out.println("Oh my dear!");
		}
	}
}
