Following China's defeat by the British in the Opium Wars (1839-42 and 1856-60), European powers gained extraordinary economic, military and legal privileges on Chinese soil, especially along the coast in the treaty ports. Officially, the Chinese Empire was still an independent power, but in reality it was at the mercy of other powers and their treaties, which were backed up by "gunboat diplomacy" or armed powers.