public void run() {
	
		try {
			oos = new ObjectOutputStream(connection.getOutputStream());
			ois = new ObjectInputStream(connection.getInputStream());
		}
		catch (Exception e) {
			e.printStackTrace();
			return;
		}
		
		try {

			BufferedInputStream bis = new BufferedInputStream(connection.getInputStream());
			while (true) {

				// Process the command that was sent by the client.
				// First preference to requests from client
				ServerCommandInterface sci = null;
				
				if (exitThread == true) {
					cleanup();
					return;
				}
				
				if (bis.available() > 0) {
					sci = (ServerCommandInterface)ois.readObject();
				}
				else if (!commandsQueue.isEmpty()) {
					sci = (ServerCommandInterface)commandsQueue.remove();
				}

				if (sci != null) {
					System.out.println( "Thread processing command: " + sci);
					sci.process(this);
					System.out.println( "Done processing command: " + sci );
				}
			}
		}
		
		// EOFException is encountered when this thread was expecting a command from the
		// client and suddenly the stream got closed. In that case, it can be assumed that
		// the client got disconnected.
		catch (EOFException e) {
		
			cleanup();
			return;
		}
		catch (SocketException e) {
		
			cleanup();
			return;
		}
		
		catch (Exception e) {
				
			// Encountered an exception. Probably I should close the connection and
			// remove the client.
			cleanup();
			return;
		}
	}