public void run(){
		try{
			socket.setSoTimeout(5000);
			username = in.readLine();
			if(server.clients.hasUser(username)){
				out.println("Chat has already user with name " + username);
				System.out.println("Socket closed: " + socket);
				server.addMsgToMsgsQueue("Socket closed: " + socket);
				socket.close();
				throw new IOException();
			}
			server.clients.addUser(username);
			server.clients.distribution("Joined:" + username +  " " + socket);
			server.addMsgToMsgsQueue("Joined:" + username);
			System.out.println("Joined:" + username);
			while(true){
				String s = in.readLine();
				if(!s.equals("")){
					server.addMsgToMsgsQueue(s);
					server.lastMessage.add(s);
					server.clients.distribution(s);
				}else{
					sendMsg("");
				}
				Thread.currentThread().sleep(100);
			}
		
		} catch (InterruptedException e) {
			e.printStackTrace();
		}catch(SocketTimeoutException e){
			e.printStackTrace();
		}catch (IOException e) {
			e.printStackTrace();
		}finally{
			if(!socket.isClosed()){
				try {
					server.clients.distribution("Leave: " + username);
					server.addMsgToMsgsQueue("Leave: " + username);
					server.addMsgToMsgsQueue("Socket closed: " + socket);
					System.out.println("Socket closed: " + socket);
					socket.close();
					server.clients.remove(username);
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
				
		}

	}