public void run() {
		try {
			out = new PrintWriter(socket.getOutputStream(), true);
            in = new BufferedReader( new InputStreamReader(socket.getInputStream()));
            String inputLine = "" , outputLine;
            // Do the login name
            outputLine = "Please enter a username" ;
        	out.println(outputLine);
        	while((inputLine = in.readLine()) != null && server.checkUser(inputLine)) {
        		outputLine = "'" + inputLine + "' is taken. Please enter a unique username" ;
        		System.out.println(outputLine);
            	out.println(outputLine);
        	}
        	if(inputLine != null) {
	    		server.addUser(inputLine);
	    		server.systemMessage("Added user " + inputLine);
	    		out.println("Welcome to ChatServer!");
	    		username = inputLine ; 
	    		loggedin = true ;
	            while((inputLine = in.readLine()) != null && loggedin) {
	            	if(inputLine.equals("-exit"))
	            		break ;
	            	server.sendMessage(this, inputLine);
	            }
        	}
        	server.removeUser(username);
            loggedin = false ;
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
			System.err.println("Concurrency error");
		}
	}