I did a lot of search, found some topics like Detect that the Internet connection is offline? but they don't solve my problem.
When I took a look at Google Doc(maybe Gmail use the same way) product, its Internet connectivity checker looks great and almost got notified in real time once you turned off your WiFi.
If you turn on Chrome's Network Monitor, there are http requests: https://0.docs.google.com/document/d/1muWJEAPZU2meqlBg4_69osnscaM1GpxkOK--H7r-f44/bind?id=... and restarts every minutes(55 seconds around)
When you turn off the WiFi, the long polling request get interrupted by ERR_NETWORK_CHANGED.
I try to implement something like this on my own machine, but my long polling request never got interrupted or exception (I use tornado web framework and google chrome)
Is there anyone can show me the magic part that how Google doc checks its connectivity?