How does the presence mechanism work?

If a user has sent his presence to the server, then the server will push this information to his roster.But in contrast, when a user has just logged in, how did he get the presence about his roster?

This is all part of the XMPP protocol. By sending your presence, you’'re telling the server to start sending you presence information from other users. Check out the full details at http://www.xmpp.org.

Regards,

Matt