They remained independent because they served as a buffer between French Indochina and British empire and due to the reforms of Rama IV and Rama V. Cool fact: they actually have managed to get those two countries to fight between themselves over Thailand.