Check out example codes for "html5 web socket". It will help you in understanding the concepts better.
Code Example 1
var i = 0;
function timedCount()
{
i = i + 1;
postMessage(i);
setTimeout("timedCount()",5000);
}
timedCount();
Learn ReactJs, React Native from akashmittal.com