In which condition client session is closed

Hello All,

Can anyone guide me about client sessions. I want to it configurable When a user send logout command. Either he is online on sms or logout. Is there any way to keep a user online after closing his client tcp connection so that his messesge can be send on his registered mobile phone.