Despite the recent advances in automatic sleep staging, few studies have focused on real-time sleep staging to promote the regulation of sleep or the intervention of sleep disorders. In this paper, a novel network named SwSleepNet, that can handle both precisely offline sleep staging, and online sleep stages prediction and calibration is proposed. For offline analysis, the proposed network coordinates sequence broadening module (SBM), sequential CNN (SCNN), squeeze and excitation (SE) block, and sequence consolidation module (SCM) to balance the operational efficiency of the network and the comprehensive feature extraction. For online analysis, only SCNN and SE are involved in predicting the sleep stage within a short-time segment of the recordings. Once more than two successive segments have disparate predictions, the calibration mechanism will be triggered, and contextual information will be involved. In addition, to investigate the appropriate time of the segment that is suitable to predict a sleep stage, segments with five-second, three-second, and two-second data are analyzed. The performance of SwSleepNet is validated on two publicly available datasets Sleep-EDF Expanded and Montreal Archive of Sleep Studies (MASS), and one clinical dataset Huashan Hospital Fudan University (HSFU), with the offline accuracy of 84.5%, 86.7%, and 81.8%, respectively, which outperforms the state-of-the-art methods. Additionally, for the online sleep staging, the dedicated calibration mechanism allows SwSleepNet to achieve high accuracy over 80% on three datasets with the short-time segments, demonstrating the robustness and stability of SwSleepNet. This study presents a real-time sleep staging architecture, which is expected to pave the way for accurate sleep regulation and intervention.