public void run(){
		//long start=System.currentTimeMillis();

		try {
			writer = new PrintWriter(socket.getOutputStream(), true);

			reader = new BufferedReader(new InputStreamReader(System.in));	
			String input;	

			/*
			//registering
			writer.println(parser.parse("!register"));
			System.out.println("waiting for registration");
			boolean ack=ClientStatus.getInstance().isAck();
			while(!ack){

				//System.out.println(ack);
				if(System.currentTimeMillis()-start > 5000){// timeout
					throw new CommandException("registration failed! Timeout!");
				}
				ack= ClientStatus.getInstance().isAck();

			}
			*/
			

			System.out.println("READY for Input!");

			while((input = reader.readLine()) != null) {

				if(input.equals("!end")) {					
					if(!ClientStatus.getInstance().getUser().equals("")){
						writer.println("!logout");
						ClientStatus.getInstance().setKill(true);
					}
					break;
				}
				else{
					if(input.length()>0){
						String query=parser.parse(input.trim());
						if(query.length()>1)
							writer.println(query);
					}
					else System.out.println("");

				}
			}
		}catch(SocketException e){
			System.out.println("socket gone");
			return;
		}
		catch (IOException e) {
			System.out.println("IO:....");
			return;
		}
		/*catch (CommandException e) {
			System.out.println(e.getMessage());
			return;
		}
		*/
		finally{
			if(!socket.isClosed())
				close();
		}
	}