Ok I have read how China was for years the prominent nation of the earth my question is when did China realize that the West had over taken them and what was their reaction to it?
The key question here is 'in what sense'? Do we mean in economic terms, military terms or diplomatic terms? Well, I'm not particularly well-versed in Chinese political and economic thought (and in any case writing on fiscal policy was generally a bit behind) so I'll mainly tackle the military and diplomatic angles.
Chinese scholars had recognised, to some extent or another, the technological superiority of Western militaries since the early nineteenth century. Xu Naiji, the opium legalisation advocate, noted in 1836 the likelihood that, in the event of a crackdown, European traders could gain control of an island like Hong Kong or Dinghai for use as a smuggling base, implicitly suggesting that the Qing could not mount a sufficient response. His contemporary, Xiao Lingyu, was particularly impressed by British weaponry, particularly the rate of fire of British muskets (which were flintlocks as opposed to the matchlocks still the norm in Chinese use) and the accuracy of British naval artillery (not yet rifled but still of much higher quality production than Chinese pieces.) Yet neither was particularly worried by this or proposed any significant reforms to close the gap, as in their view war with Britain was virtually inconceivable so long as positive trade relations continued.^1
Something that might surprise us today, given the emphasis modern Chinese historiography places on the First Opium War (1839-42), is that the war itself produced very little impetus for reform. The obvious reason for this is that it wasn't even considered a 'war' in the proper sense until the 1910s, and until then it was generally dismissed a 'border disturbance' or similar – indeed, at the time officials called the British 'rebels' rather than recognising a conventional interstate conflict in the way the British did.^2 Moreover, the way the Qing government was set up both prevented affairs on the ground from significantly influencing decisions at the centre and gave those at the frontier minimal freedom of action beyond what the centre specified. Consequently, although officials at the front very quickly realised the war was unwinnable, they had neither the authority nor the influence to respond effectively, and the censure of most of those who did serve at the front (those who survived, anyway) left the central government critically uninformed and seeing little reason for a need to change.^3
Nor, indeed, did the public at large, even in areas hit by the war. Hong Xiuquan and Feng Yunshan, the early ideological heads of the Taiping Heavenly Kingdom (1851-64), lived very near the initial theatre of war around Canton, yet neither (to my knowledge at least) made any sort of statement regarding recent troubles with Britain as a justification for the Qing's overthrow. Early diplomatic contacts with the West largely reiterated the haughty rhetoric of the empire, and it would not be until the involvement of Hong Rengan, who had experience working with Westerners in Hong Kong, in 1859 that the Taiping softened their diplomatic approach to a more egalitarian view of interstate relations.^4 Hong saw Chinese weakness as only a temporary state of affairs that could be resolved by the adoption of Western technology and institutions, like railways, steamships, and modern banks, but in the end the defeat of the Taiping prevented anything from coming of this.^5
Whilst there would be a Westernisation of both diplomatic institutions and military technology during the 1860s, one would be hard-pressed to link this primarily to the Second Opium War (1856-60). However, it is clear that there was a trend towards adopting Western practices. Ongoing wars with the Taiping Heavenly Kingdom, the Nian rebels, the Panthay Sultanate and, from 1862 onwards, Muslim rebels on the western frontiers meant that the enlistment of Western support and the modernisation of Qing armies was probably done for more inward-focussed reasons than a purely impact-response view of Chinese history would suggest. Hence the establishment of the Zongli Yamen (a somewhat ad hoc foreign office) in 1861 by Prince Gong and the adoption of Western arms and drill by both fully-Westernised forces like the Ever-Victorious and Ever-Triumphant Armies and Han militia armies like the Xiang, Huai and Chu Armies. The degree to which Western ideas were seen as superior is quite clear from the language of command used: in the Huai Army, for example, was found the term 'fa-wei-ma-qi' – a direct transliteration of 'forward march'!^6
Ultimately the idea of China's being eclipsed by the West in a more general sense only became widespread first under the Republicans, who emerged in the 1890s, and then the Communists. Republican intellectuals saw China as not just geopolitically but categorically inferior to the West, denouncing cultural practices ranging from opium-smoking to foot-binding to Confucian philosophy, and advocated a more Western, 'modernisation'-based approach. On the other hand, the Communist Party's creation of the 'century of humiliation' from 1839/42 to 1949 was essentially just a means of legitimising Communist Party rule as a reversal of China's apparent humbling at the hands of foreign powers.
Sources, Notes and References: